- 26 Sep 2023
- 4 Minutes to read
Execute Shell scripts on macOS devices with Scalefusion
- Updated on 26 Sep 2023
- 4 Minutes to read
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.
- Create a Mac Device Profile
- The devices should have Mac version 10.15 and above
- Mac Devices should be enrolled with Scalefusion
- The latest version of the Scalefusion - MDM Client is installed on the enrolled Mac device.
- Make sure that you have the required storage in the Enterprise Store. To learn more about space allocation, please visit here.
- Enterprise App package and the following details from the developer,
- shell script (.sh) file
- File size should be less than 2GB
Uploading and Installing a Shell script
Follow the steps below to upload and install a Shell script,
- Sign In to Scalefusion Dashboard. Navigate to Application Management > Enterprise Store
- Click on Upload New App > Upload macOS App
- In the Upload macOS app window, choose Upload Shell script to upload the .sh file that will execute the script.
- This will open the Upload Shell Scripts wizard. Follow the steps below to upload the file.
- Enter Script Name: This is used for identification inside Device Profiles
- Upload Scripts File: Select how you want to upload the script file,
- Upload Local File: Use this option if you have the .sh file available locally.
- 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.
- Run Script as signed-in user: Select whether the script has to be run as signed-in user or not:
- Yes (default): Permissions of the logged-in user will be used at the time of script execution.
- No: The script will be executed at the root level.
- Configure a Schedule: Configure when the script should be executed.
- Run Once On Publish: The script will be executed only once on the device when it is published from the dashboard.
- Run At Every Login: The script will be executed every time the user logs into their Mac machine.
- Run On Schedule: You can select on which days the script should be executed.
- Select Day: Select day(s) from Monday to Sunday.
- Configure Time(s): You can set a time for executing the script and can add multiple time periods.
- Click Save
- 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.
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.
Uninstalling Shell Script
Shell scripts can be uninstalled from the devices remotely. Follow the steps below to Uninstall a previously deployed script,
- Navigate to Application Management > Enterprise Store
- Click on the Shell script that you uploaded earlier to see the script information wizard, Click on Uninstall.
- Select the Device Profiles where you want to uninstall the application and click on Uninstall.
- 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,
- In the script information wizard, Click on the Delete button.
- You will get a confirmation box. Click OK.
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.