Lab 7: Using scripts and sensors

Objectives and Tasks

Sensors and Scripts

  1. Create a sensor reporting the free disk space available on a macOS device.

  2. Create a sensor reporting the build version of the operating system.

  3. Create a sensor reporting the CPU architecture of a macOS device.

  4. Create a script for macOS in the Workspace ONE console.

For privacy reasons, sensors are not supported on employee-owned devices.

If you don’t have an enrolled macOS in your lab environment, you won’t see the sensor results in the Workspace ONE console. Nevertheless, you should still proceed with performing the tasks to learn how to deploy sensors.

Task 1: Create a sensor reporting the free disk space available on a macOS device

In this exercise, you will create a sensor that will report the available free disk space on macOS devices.

To create the sensor:

  1. In the Workspace ONE console, click on Resources.

  2. Select Sensors.

  3. Click Add and select macOS from the dropdown menu.

  4. Enter system_disk_free_space{labid} as the sensor name. Click Next.

  5. From the Language dropdown, select Bash.

  6. Set the Execution Context to System.

  7. Select String from the Response Data Type.

  8. Paste the following code into the Code window.

#!/bin/bash

free_space=$(/usr/sbin/diskutil info /| grep 'Available Space:\|Free Space' | awk '{print $4, $5}')
echo $free_space

# Description: Returns free disk space of root volume '/'
# Execution Context: SYSTEM
# Execution Architecture: UNKNOWN
# Return Type: STRING
Click to copy
  1. Click Next.

  2. Click Save & Assign.

  3. Click New Assignment.

  4. Name the assignment All Corporate macOS Devices.

  5. Click in the Select Smart Group field and select Corporate-owned macOS Devices. Click Next.

  6. For Triggers, select Login and Log Out. This will trigger the sensor to report its value to Workspace ONE whenever an end user logs in or out of their device.

  7. Click Save.

  8. Click Close.

Task 2: Create a sensor reporting the build version of the operating system

In this exercise, you will create a sensor that will report the build version of the operating system on macOS devices.

To create the sensor:

  1. In the Workspace ONE console, click on Resources.

  2. Select Sensors.

  3. Click Add and select macOS from the dropdown menu.

  4. Enter os_build_version{labid} as the sensor name. Click Next.

  5. From the Language dropdown, select Bash.

  6. Set the Execution Context to System.

  7. Select String from the Response Data Type.

  8. Paste the following code into the Code window.

#!/bin/bash

buildv=$(/usr/bin/sw_vers -buildVersion)
echo $buildv

# Description: Returns the OS build version
# Execution Context: SYSTEM
# Execution Architecture: UNKNOWN
# Return Type: STRING
Click to copy
  1. Click Next.

  2. Click Save & Assign.

  3. Click New Assignment.

  4. Name the assignment All Corporate macOS Devices.

  5. Click in the Select Smart Group field and select Corporate-owned macOS Devices. Click Next.

  6. For Triggers, select Login. This will trigger the sensor to report its value to Workspace ONE whenever an end user logs in to their device.

  7. Click Save.

  8. Click Close.

Task 3: Create a sensor reporting the CPU architecture of a macOS device

In this exercise, you will create a sensor that will report the CPU architecture of managed macOS devices.

To create the sensor:

  1. In the Workspace ONE console, click on Resources.

  2. Select Sensors.

  3. Click Add and select macOS from the dropdown menu.

  4. Enter system_cpu_arch{labid} as the sensor name. Click Next.

  5. From the Language dropdown, select Zsh.

  6. Set the Execution Context to System.

  7. Select String from the Response Data Type.

  8. Paste the following code into the Code window.

#!/bin/zsh

PROC=$(/usr/sbin/sysctl -n machdep.cpu.brand_string)

if grep -q "Apple" <<< "$PROC"; then
	echo "arm64"
else
	if grep -q "Intel" <<< "$PROC"; then
    	echo "x86_x64"
    else
    	echo "unknown_cpu"
    fi
fi

# Description: Returns CPU processor architecture. Either arm64, x86_64 or unknown_cpu.
# Execution Context: SYSTEM
# Execution Architecture: UNKNOWN
# Return Type: STRING
Click to copy
  1. Click Next.

  2. Click Save & Assign.

  3. Click New Assignment.

  4. Name the assignment All Corporate macOS Devices.

  5. Click in the Select Smart Group field and select Corporate-owned macOS Devices. Click Next.

  6. For Triggers, select Startup. This will trigger the sensor to report its value to Workspace ONE during device startup.

  7. Click Save.

  8. Click Close.

Once the sensors are triggered on the devices, you will see values populated in the Sensors tab under Device Details.

Task 4: Create a macOS script in Workspace ONE UEM

If this is the first time you have accessed the Scripts interface, you might be prompted with an information screen with helpful links to get you started with the Scripts feature in Workspace ONE. Click Get Started to proceed.

For this exercise, you will use a simple script that creates a text file on the desktop of the device’s logged-in end user.

To create a script:

  1. In the Workspace ONE console, select Resources. Then, click Scripts.

  2. Click Add, and select macOS from the dropdown menu.

  3. Name the script Create-File-On-Desktop(labid). Leave the App Catalog Customization disabled. Click Next.

  4. Set the Language to Bash, and the Execution Context to System.

  5. Paste the following script into the Code window.

#!/bin/sh
loggedInUser="root"
while [[ "$loggedInUser" == "root" ]];
do
sleep 10
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
done
touch /Users/$loggedInUser/Desktop/textfile.txt
Click to copy
  1. Click Next.

  2. Click Save.

  3. In the Scripts list, check the new script you just created, and click Assign.

  1. Click New Assignment. Name the assignment All macOS Devices.

  2. For Select Smart Group, click in the search box. From the list of Assignment Groups that appear, select Corporate-owned macOS Devices.

  3. Click Next.

  4. Check Run Once Immediately.

  5. Click Add.

  6. Click Save & Publish, and then click Publish.

0 Comments

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.