Execute Shell scripts on macOS devices with Scalefusion
  • 26 Sep 2023
  • 4 読む分
  • PDF

Execute Shell scripts on macOS devices with Scalefusion

  • PDF

The content is currently unavailable in Ja - 日本語. You are viewing the default English version.
記事の要約

In the Mac ecosystem, Shell scripts are a useful tool to perform system-level tasks, finding patterns in a file, processing the data in a file based on the user inputs, etc. With shell scripts, you can combine many common tasks into one script, saving you time and possible errors when performing similar tasks over and over.

Moving a step forward towards enhancing Device Management of Mac devices, Scalefusion MDM enables uploading shell script files and then executing those scripts remotely on Scalefusion-managed Mac devices.

This document describes how Shell scripts can be uploaded and deployed on managed Mac devices.

Prerequisites

  1. Create a Mac Device Profile
  2. The devices should have Mac version 10.15 and above
  3. Mac Devices should be enrolled with Scalefusion
  4. The latest version of the Scalefusion - MDM Client is installed on the enrolled Mac device.
  5. Make sure that you have the required storage in the Enterprise Store. To learn more about space allocation, please visit here.
  6. Enterprise App package and the following details from the developer,
    1. shell script (.sh) file
    2. File size should be less than 2GB

Uploading and Installing a Shell script

Follow the steps below to upload and install a Shell script,

  1. Sign In to Scalefusion Dashboard. Navigate to Application Management > Enterprise Store
  2. Click on Upload New App > Upload macOS App
  3. In the Upload macOS app window, choose Upload Shell script to upload the .sh file that will execute the script.
  4. This will open the Upload Shell Scripts wizard. Follow the steps below to upload the file.
    1. Enter Script Name: This is used for identification inside Device Profiles
    2. Upload Scripts File: Select how you want to upload the script file,
      1. Upload Local File: Use this option if you have the .sh file available locally.
      2. Shell Script URL: Use this option if you have hosted/uploaded the file on your servers and have a link that is accessible publicly. Provide the URL to the externally hosted file. This URL should be publicly available.
    3. Run Script as signed-in user: Select whether the script has to be run as signed-in user or not:
      1. Yes (default): Permissions of the logged-in user will be used at the time of script execution.
      2. No: The script will be executed at the root level.
    4. Configure a Schedule: Configure when the script should be executed.
      1. Run Once On Publish: The script will be executed only once on the device when it is published from the dashboard.
      2. Run At Every Login: The script will be executed every time the user logs into their Mac machine.
      3. Run On Schedule: You can select on which days the script should be executed.
        1. Select Day: Select day(s) from Monday to Sunday.
        2. Configure Time(s): You can set a time for executing the script and can add multiple time periods.
    5. Click Save
  5. Once you click on SAVE, Scalefusion will process the script, and if the processing succeeds, then the following dialog will be shown. Here you can select the Device Profiles where you want to publish the script and click Publish

Checking Execution Status

After publishing, you can check the status of whether the shell script pushed from the enterprise store has been executed or not by using the View Status option,

A script that is well executed on the device shows the status as Executed or Downloaded, and if not, then the status shows as either Pending, Executing, or Execution Failed.

On Device

The shell script executed will reflect on the device, or the data fetched through the script will be visible on the dashboard. For example, in the above step, we have uploaded and published a script to get the battery status from the managed device. Navigating to the View Status and clicking on the View Details hyperlink, we are able to see the details of the battery health in the Output tab.

If the script fails to execute, you will be able to see the reason for the same in the Error tab.

Note that the device needs to be active and online for the scripts to be executed on it.


Uninstalling Shell Script

Shell scripts can be uninstalled from the devices remotely. Follow the steps below to Uninstall a previously deployed script,

  1. Navigate to Application Management > Enterprise Store
  2. Click on the Shell script that you uploaded earlier to see the script information wizard, Click on Uninstall.
  3. Select the Device Profiles where you want to uninstall the application and click on Uninstall.
  4. Once this step is done, the script will no longer be force-installed and executed on the devices.

Deleting Shell Script

A Shell script file can also be deleted. It deletes the script file from the Enterprise Store on the Scalefusion Dashboard as well as from the device. To delete a script file,

  1. In the script information wizard, Click on the Delete button.
  2. You will get a confirmation box. Click OK.

Dynamic Scripts

The Shell scripts are static in nature. That is, the same script gets executed on all devices. However, in some cases, the admin may want to pass some dynamic values based on the device or user of the device where the script is executing. Scalefusion now extends the support of Custom Fields to allow for dynamic substitution using our agent. For example,

echo "User Id is %$device.Id%"
echo "User Name is %$device.Name%"
echo "User Surname is %$device.surName%"

To know more about the Custom Fields feature and how to use it, please refer to our guide here.


この記事は役に立ちましたか?