Scripts



Scripts

SimpleMDM supports the ability to run remote scripts on devices without requiring a third-party agent to be installed to deploy them. Scripts can be scheduled to run immediately, at a specific date or time in the future, or recurringly.

Creating A Script

To create a new script:

  1. Navigate to the Scripts section on the left side of the screen in the interface.
  2. Click "Create Script."
  3. Give the script a meaningful name.
  4. Click "Choose File" and upload your script file, or type/paste your script directly into the text editor field. Scripts must start with a shebang (#!/bin/bash).
  5. Click "Save."

Once you have created your script, you will be able to use it to create a job to run on your devices.

A Note On Restarts

If your script contains a reboot, shutdown, or similar command, SimpleMDM won't be able to detect whether or not that script has completed. The script, however, will not be re-run. As a result, there is no risk of a loop.

Creating A Job

To create a job to run a script:

  1. Click Jobs under the Scripts section of the menu.
  2. Click “Create Job."
  3. Give the job a name.
  4. Click the "Script" dropdown and select the name of a script that you have previously created.
  5. In the "Run On" field, type the names of any assignment group (from the Assignments page), device group, or individual devices that you would like to run the script on.
  6. In the “Run Options” field, select one of:
    • “Run ASAP” - This will attempt to run the script immediately on the selected devices.
    • “Run Later” - This will run the script once at a later time and date of your choosing.
    • “Run Recurringly” - This allows you to create a recurring schedule for which to run the script.
      • When choosing “Run recurringly”, the “End recurring date” is the date that the recurring script job will stop running. Leave this blank if you want the job to run indefinitely. Jobs can be canceled later as needed.
  7. Next is the "Auto Attributes' option. You can check this box if you want to store script outputs in a custom attribute on the device record.
  8. (Optional) “Cancel job if not started after” allows you to specify a time after which the job will be canceled if it has not already been executed. For example, if a job is scheduled to run at Monday at 6am but the device is offline at the time and you do not want it to run during work hours, you can optionally set this to 2 hours to avoid it executing once the user is online. In this example, the command will be deleted from the device’s queue after 2 hours if it has not already been executed.

View Job Information

To view existing job schedules, click the “Scheduled” tab. 
  • This section shows a list of scheduled jobs. 
  • To edit a scheduled job, click the job name. 
  • To delete a scheduled job, click the Actions button (3 vertical dots) and select “Delete”. 
  • To stop a job from executing temporarily, click the Actions button (3 vertical dots) and select “Pause”. To reactivate a paused job, click the button again and select “Resume”. 
To view information about jobs that have already attempted to be executed, click the “History” tab. 
  • Click the job name to get information about the job. 
    • On the Job Details page, you can see information such as: 
      • Script name 
      • "Created At" timestamp 
      • Which user created it 
      • How many devices it was run on 
      • Job Status (Pending, Success, Error) 
        • Click the Devices tab to view the devices that it was run on. Click the Script tab to view the script itself. 
  • Jobs with a “Pending” status can be canceled by clicking the Actions button (3 vertical dots) and selecting “Cancel”. 

Script Response Messages

SimpleMDM will store the response message output and code that a script generates. To view the output, visit the Job Details screen, navigate to the Devices tab, and select the associated log for a device. The log will include the script output and response code.

Custom Attributes

The Scripts feature supports the use of custom attributes. To allow custom attributes to be processed within a script, check the box labeled "Enable custom attributes" in the script settings.

Auto Attributes

SimpleMDM now supports the ability to run a script and save the output/device response in a custom attribute. This is configurable using the Attribute Options field on the Scripts > Jobs page.

To store a job output in a custom attribute:

  1. Create a custom attribute by navigating to Configs > Attributes on the left side of the screen in the interface.
  2. Navigate to Jobs under the Scripts section of the menu.
  3. Check the box labeled Store script output in custom attribute on device record.
  4. In the Store output in field, select your custom attribute.
    • If you need to sanitize the script output using regex, use the Sanitize output with field to configure as needed.
  5. Configure the other job settings as needed and run it immediately or at a scheduled time.

When devices respond with an output, the output will be stored in a custom attribute on the device record. 

Still have a question or want to share what you have learned? Visit our Community Discord to get help and collaborate with others.