Deploy Linux Shell scripts using Scalefusion
  • 17 Jan 2025
  • 6 Minutes to read
  • PDF

Deploy Linux Shell scripts using Scalefusion

  • PDF

Article summary

Shell scripts are a powerful tool for automating tasks and simplifying configuration and can be used to automate almost any task in the Windows ecosystem. With a carefully designed script, you can automate various administrative tasks like adding users, installing applications, checking for OS updates to name a few. It becomes imperative for an MDM solution to provide support to be able to push scripts and then view detailed output.

Scalefusion offers you a powerful interface that lets you push scripts to all your devices and view detailed output on each of them. Follow the steps below to deploy a script and view the output.

Prerequisites

  1. Enroll a Linux Device.

  2. Scalefusion Enterprise Plan.

Step 1: Upload and Deploy the script

  1. Navigate to Application Management > Enterprise Store , click on Upload New App and select Upload Linux Script

  2. 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 and upload the scripts file (.sh file) available how you want to upload the script file,

    3. Execution Level: Select one from the following:

      1. Device: The script will be executed for all existing users on the device

      2. User: The script will be executed for the user who is logged in on the device

    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


  3. 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

    1. Once a script is published a push is sent to the devices and on all devices which are online the execution will start.

Once a script is published to the profile, all new devices enrolled here after will automatically execute this script post enrollment.

Using Custom Properties in scripts

The Shell scripts are static in nature. That is, the same script gets executed on all devices. However, in some cases, IT admins may want to pass some dynamic values based on the device or user of the device where the script is executing. You can use %$device.% and %$user.% custom properties in the scripts and those would be dynamically replaced at a per device/user level. Ensure that custom properties are enclosed within percentage symbols (%) both before and after the property name.

For example, the below script will only display battery information on devices where the custom device property "user" is set to "abc". Otherwise, it prints the message "user is not abc".

#!/bin/bash

if [ "%$device.user%" = "abc" ]; then

# show battery
upower -i upower -e | grep 'BAT' ; upower -i $(upower -e | grep BAT) | grep --color=never -E "state|to\ full|to\ empty|percentage"

else
echo "user is not abc"
fi

Note: Custom Properties for Linux devices can be added from Device Info under Devices section.

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

Step 2: View Status & Unpublish

  1. All the uploaded scripts appear in the Enterprise store section. Clicking on Publish allows you to view details of the script.

    1. Publish: Use this option to publish the script to device profiles.

    2. Unpublish: Use this option to unpublish the script from device profiles.

      Please note that this option would not undo the changes that the script did. Un-publishing would cause the script not be executed on the newly enrolled devices.

    3. Summary: The summary pane gives you the information and current execution status,

      1. Size: Indicates the size of script

      2. Uploaded On: The time when this script was uploaded.

      3. Installed On: Number of devices where it is executed.

      4. Published To: Number of devices where it is published to.

        The Installed On and Published To stats are retained even after a script is unpublished.

    4. Preview: Use this option to preview the script that you uploaded.

    5. View Status: Use this option to get detailed status of the script execution on each device and the output.

      1. Click on View Detailsto check the output of the script execution.

        1. Stdout: This tab gives you the output of the script.

        2. Stderr: This tab gives you the error if any from the script execution.

Frequently Asked Questions

  1. Question: How often the script is executed?

    1. For now the script is only executed once the device receives it. We are looking at adding support for scheduling.

  2. Question: Why does not the script execute again even when we Unpublish and Publishit again on the same profile?

    1. Our current implementation requires you to delete the script completely and upload it again on the same profile if you want to execute it again.

Helper Scripts

We have curated some helper scripts, that lets you perform some administrative tasks readily. Please click on the links below to download the scripts and before using them, please replace the placeholders in them.

Please ensure that you use a UTF-8 editor like gedit on Ubuntu or notepad++ on Windows or Sublime Text so as to ensure that the generated script file is UTF-8 encoded.

  1. Click on the Script link in the Script column which opens the script in a new browser window.

  2. Copy the contents to a UTF-8 editor like notepad++ OR Sublime Text in Windows or geditin Ubuntu

    1. If you are using notepad++ then use the bottom right panel to change the type to Unix (LF)

  3. Update the script and replace the placeholders as required.

  4. Upload the script to Scalefusion Dashboard and deploy it to the devices.

Scripts

Description

Allow Keyboard & Mouse

Use this script to allow input devices when you choose to block the USB devices via the device profile.

Create a Local Standard user

Use this script to create a local user with standard privileges.

Create a Local Sudo/Root User

Use this script to create a local user with Sudo/root privileges.

Change password for a user

Use this script to change the password for a local user.

List All Users

Use this script to retrieve the list of users on each device.

Install Google Chrome

Use this script to install Google Chrome.

Install Any App using Flatpack

Use this script to install flatpack and install any applications.

List Available updates

Use this script to list available OS and app updates.

Install All updates silently

Use this script to install all available updates silently.

Block URLs/Websites

Use this script to block the websites defined in the script.

Unblock Websites

Use this script to unblock the websites defined in the script, that may have been blocked earlier.

Lock active user session

Use this script to remotely lock the currently active user session on a Linux system.

Update Host names

Use this script to remotely update the Host names.

Delete Files/Folders

Use this script to remotely delete files and/or folders.

Temporary Sudo access for specific user

Use this script to give temporary Sudo access for specific user.

Block Multiple apps

Use this script to block multiple apps from launching.

Allow selected applications

Use this script to allow selected applications.

Enable Bluetooth

Use this script to enable Bluetooth.

Disable Bluetooth

Use this script to disable Bluetooth.

Lock user account

Use this script to lock a user account.

Unlock user account

Use this script to unlock a user account.

Delete user account

Use this script to delete a user account.

Check System service

Use this script to check system service of the device(s).

Start System service

Use this script to start the System services.

Download & set wallpaper

Use this script to download an image from a Google Drive and automatically set it as desktop wallpaper.

Lock Folder

Use this script to lock the following folders: Documents, Downloads, Music, Pictures, Videos, snap, Public, Templates for both Standard and Sudo Users.

Unlock Folder

Use this script to unlock the following folders: Documents, Downloads, Music, Pictures, Videos, snap, Public, Templates for both Standard and Sudo Users.

Allow All Applications

The following script helps IT Admins allow all the Linux machine applications.

Notes:

1. Some of the scripts and their contents are sourced from internet and yes, our new friend ChatGPT.

2. Please validate the scripts on a test machine before deploying them on all your managed devices.

3. Scalefusion has tested these scripts, however Scalefusion will not be responsible for any loss of data or system malfunction that may arise due to the usage of these scripts.


Was this article helpful?