1. Home
  2. Knowledge Base
  3. SureMDM
  4. Android Management
  5. How to use Android Shell Scripting with SureMDM?

How to use Android Shell Scripting with SureMDM?

SureMDM supports execution of both Android Shell Script Commands and Custom SureMDM Scripts using Runscripts job. Android Shell Commands are series of scripts that executes on device within its shell and Custom SureMDM Scripts are special scripts that are specifically created and supported only within SureMDM. Jobs including these scripts can be remotely pushed to the enrolled devices for execution.

List of Android Shell Scripts:

1. List all files in sdcard

ls /sdcard

2. Create sample folder inside sdcard

mkdir /sdcard/sample

3. Change current directory

cd /sdcard/sample

4. Rename sample.txt to sample1.txt

mv /sdcard/sample.txt 
/sdcard/sample1.txt

5. Moves folder test to test1

mv /sdcard/test
/sdcard/test1

6. Delete all files inside test folder with extensions

rm -r /mnt/sdcard/test/sample.txt

7. Delete all files(even without extensions) and folders inside test folder

rm -r /mnt/sdcard/test/*

8. Delete file with name test.txt inside sdcard

rm -r /sdcard/test.txt

9. Launch specific activity

am start -n com.android.settings.Settings

10. Launch settings

am start -a android.intent.action.MAIN -n com.android.settings/.Settings

11. Launch Default HomeScreen

am start -c android.intent.category.HOME -a android.intent.action.MAIN

12. Open google.com in default browser

am start -a android.intent.action.VIEW http://www.google.com

13. Open dialer with phone number

am start -a android.intent.action.CALL tel:1234567890

14. Make call to 123

am start -a android.intent.action.CALL tel:123

15. Broadcast fake battery low message

am broadcast -a android.intent.action.BATTERY_LOW

16. Launch SureFox

am start -a android.intent.action.MAIN -n com.gears42.surefox/.SurefoxBrowser

17. Launch SureLock

am start -a android.intent.action.MAIN -n com.gears42.surelock/.ClearDefaultsActivity

18. Launch SureMDM Agent

am start -n com.nix/.MainFrm

19. Exit SureLock

am broadcast -a com.gears42.surelock.COMMUNICATOR -e password Password -e command exit_surelock com.gears42.surelock

20. Exit SureFox

am broadcast -a com.gears42.surefox.COMMUNICATOR -e password Password -e command exit_surefox com.gears42.surefox

21. Apply SureMDM Agent Settings

am broadcast -a com.nix.COMMUNICATOR -e command apply_settings -e settings_path /sdcard/NixSettings.xml com.nix

22. Apply SureMDM Agent Settings

am broadcast -a com.nix.COMMUNICATOR -e command apply_settings -e %input~text% -e password %input~text% com.nix

23. Change Polling mechanism to periodic polling

am broadcast -a com.nix.COMMUNICATOR -e command change_nix_settings -e setPollingType 1 -e setPeriodicPollingIntervalInMins %input~text% -e password %input~text% com.nix

24. Change Polling mechanism to Normal polling

am broadcast -a com.nix.COMMUNICATOR -e command change_nix_settings -e setPollingType 0 -e password Password com.nix

25. Change Polling mechanism to Periodic ,Device Name ,Security Type to Http.

am broadcast -a com.nix.COMMUNICATOR -e command change_nix_settings -e setDeviceName %input~text% -e setPollingType 1 -e setPeriodicPollingIntervalInMins %input~text% -e useSecureProtocol %input~text% -e password %input~text% com.nix

26. To Stop SureMDM Agent Service

am broadcast -a com.nix.COMMUNICATOR -e command change_nix_settings -e startNix false -e password Password com.nix

27. Start SureMDM Agent Service

am broadcast -a com.nix.COMMUNICATOR -e command change_nix_settings -e startNix true -e password Password com.nix

28. Script to change SureMDM Agent Settings Password

am broadcast --user 0 -a com.nix.COMMUNICATOR -e command change_nix_settings -e startNix true -e password Password com.nix

29. Script with Password Authentication

am broadcast -a com.nix.COMMUNICATOR -e command change_nix_settings -e setPollingType 0 -e password Password com.nix

30. Send Messages

am broadcast -a com.nix.COMMUNICATOR -e command send_message -e account_id test@test.com -e subject Test Subject -e message Test Message com.nix

31. Register Location

am broadcast -a com.nix.COMMUNICATOR -e command register_location -e locations 24,24\n60,60\n...80,80// 24,24,2016-08-24 02:05:30 - latitude,longitude,yyyy-MM-dd HH:mm:ss com.nix

32. Start SureMDM Agent

am broadcast -a com.nix.COMMUNICATOR -e command change_nix_settings -e startNix true com.nix

33. Set Device Name

am broadcast -a com.nix.COMMUNICATOR -e command change_nix_settings -e setDeviceName test com.nix

34. Set Polling Type

am broadcast -a com.nix.COMMUNICATOR -e command change_nix_settings -e setPollingType %input~text% com.nix

35. Set Periodic Polling Interval in Minutes

am broadcast -a com.nix.COMMUNICATOR -e command change_nix_settings -e setPeriodicPollingIntervalInMins 1234 com.nix

36. Use Secure Protocol

am broadcast -a com.nix.COMMUNICATOR -e command change_nix_settings -e useSecureProtocol TRUE com.nix

37. Open SureLock settings from MDM Without having to enter password

am broadcast -a com.gears42.surelock.COMMUNICATOR -n com.gears42.surelock/com.gears42.surelock.service.SureLockCommunicator -e "command" "open_admin_settings" -e "password" Password com.gears42.surelock

38. Clear App Data

am broadcast -a com.nix.COMMUNICATOR -e command clearAppData -e packages package1,package2,...packageN com.nix

Note: Available for devices with KNOX and Signed Enterprise Agent.

39. Activate SureLock license with preferred activation ID as IMEI through SureMDM

am broadcast -a com.gears42.surelock.COMMUNICATOR -n com.gears42.surelock/com.gears42.surelock.service.SureLockCommunicator -e "command" "activate" -e "password" "0000" -e activation_code" "Enter Code Here" -e "prefered_activation_id" "Enter Id Here" com.gears42.surelock

40. Activate SureFox license with preferred activation ID as IMEI through SureMDM

am broadcast -a com.gears42.surefox.COMMUNICATOR -e "command" "activate" -e "password" "0000" -e "activation_code" "Enter Code Here" -e "prefered_activation_id" "Enter Id Here" com.gears42.surefox

Note: Prefered_activation_id = 0 = IMEI / 2 = WIFIMAC / 3 = BLUETOOTHMAC / 4 = GUID

41. Forget the Network

am broadcast -a com.gears42.system.eaplugin.COMMUNICATOR -e ssid "WifiNetwork SSID" -e command forget_wifi_network -f 0x00000020 com.gears42.system.eaplugin

Note: Available for signed devices with system plugin.

42. Reboot device

su -c reboot

Note: Available for KNOX and Signed Devices. Works in Device Admin and Device Owner Enrollments.

43. Install test application

su -c pm install /sdcard/test.apk

Note: Available for devices with KNOX and Signed Enterprise Agent.

44. Uninstall application

su -c pm uninstall com.example.MyApp

Note: Available for KNOX and Signed Devices. Works in Device Admin and Device Owner Enrollments.

45. Clear App Data

am broadcast -a com.nix.COMMUNICATOR -e command clearAppData -e packages package1,package2,...packageN com.nix

Note: Available for devices with KNOX and Signed Enterprise Agent.

46. Force prompt for activation of Samsung KNOX settings of SureLock

am broadcast -a com.gears42.surelock.COMMUNICATOR -n com.gears42.surelock/com.gears42.surelock.service.SureLockCommunicator -e password 0000 -e command force_knox com.gears42.surelock

Note: Available for devices with KNOX.

47. Export SureLock analytics data to File/SureMDM

am broadcast -a com.gears42.surelock.COMMUNICATOR -n com.gears42.surelock/com.gears42.surelock.service.SureLockCommunicator -e password 0000 -e command export_analytics com.gears42.surelock

48. Export SureLock Multi User analytics data to File/SureMDM

am broadcast -a com.gears42.surelock.COMMUNICATOR -n com.gears42.surelock/com.gears42.surelock.service.SureLockCommunicator -e password 0000 -e command export_analytics export_multi_user_analytics com.gears42.surelock

49. Force prompt for enabling modify system permission of SureLock (for marshmallow and above devices)

am broadcast -a com.gears42.surelock.COMMUNICATOR -n com.gears42.surelock/com.gears42.surelock.service.SureLockCommunicator -e password 0000 -e command force_modify_system com.gears42.surelock

List of Custom SureMDM Scripts:

1. Change time zone

!#suremdm
SetTimeZone(Continent/country)

2. Turn ON GPS

!#suremdm
TurnOnGPS(true)

Note: It prompts the user to enable GPS on the devices that are non-Knox/Platform signed

3. Turn ON GPS Status

!#suremdm 
TurnOnGPS(true,N)   

N value can be:0 = LOCATION_MODE_OFF1 = LOCATION_MODE_SENSORS_ONLY2 = LOCATION_MODE_BATTERY_SAVING3 = LOCATION_MODE_HIGH_ACCURACY

Note: It prompts the user to enable GPS on the devices that are non-Knox/Platform signed/

4. Change Device’s Screen Brightness

!#suremdm
SetScreenBrightness(0, 255)

5. Enable Logger

!#suremdm
enableLogger

6. Disable Logger

!#suremdm
disableLogger

7. Run Script in Sync

!#suremdm 
RunScriptsInSync(TRUE)

8. Scale Down Clicks

!#suremdm
RunScriptsInSync(TRUE)

9. Kill Process

!#suremdm
killProcess(enter pacakge1,pacakge2...pacakgen)

10. Sleep

!#suremdm
sleep(100)

11. Keep CPU On

!#suremdm
KeepCPUOn(TRUE)

12. Copy text to clipboard

!#suremdm
copyToClipboard(text)

13. RunScript to clear clipboard

!#suremdm
clearClipboard()

14. Make device screen on when remote screen is running

!#suremdm
RemoteScreenDeviceSleep(FALSE)

15. Launch app by package name or app name

!#suremdm
launch(package/appName)

16. Ignore SureMDM Agent app from Battery optimization

!#suremdm
forceIgnoreBatteryOptimizaion(TRUE)

17. Activate admin of SureMDM SureMDM Agent Samsung Verison on Device:

!#suremdm
activateadmin(com.gears42.nixsam)

18. Ignore SureMDM Agent app from Battery optimization with true/false

!#suremdm
forceIgnoreBatteryOptimization(true/false)

19. Change SureMDM Agent Service Restart Time

!#suremdm
NixServiceRestartTime(TimeInMinutes)

20. Wake the screen up and even to turn the screen off

!#suremdm
screen(ON/OFF)

21. Turn bluetooth On/Off on the device

!#suremdm
Bluetooth(on\off)

22. Wrong security type

!#suremdm
setMinimumWifiSecurity(WPA)

23. Connect to open network

!#suremdm
setMinimumWifiSecurity(open)

24. Connect to WPA network

!#suremdm
setMinimumWifiSecurity(wpa)

25. Create website shortcut and launch through Firefox

!#suremdm
CreateAppShortcut(org.mozilla.firefox,org.mozilla.firefox.App,www.42gears.com,42Gears,/storage/emulated/0/42Gears.jpg)

26. Disable Close button

!#suremdm
DisableCloseButton(true)

27. Create a short cut of a web page in Home Screen from SureMDM

 !#suremdm
CreateAppShortcut(PackageName,ClassName,Url,Title,IconPath)

28. Delete SMS

 !#suremdm
delete(sms)

29. Unlock an application:

 !#suremdm
unlockApplication(AppPackageName,AppPackagename,...)

30. Remove all users from device for Samsung devices

!#suremdm
removeAllUsersFromDevice

Note: Available for devices with KNOX.

31. Apply a restriction from creating users

!#suremdm
allowUserCreation(false/true)

Note: Available for devices with KNOX.

32. Block notifications on lock screen Except SureMDM Agent

!#suremdm
blockLockScreenNotifications(true)

Note: This feature Requires Knox Standard SDK version 5.0.

33. Show the notification on Lock Screen

!#suremdm
blockLockScreenNotifications(false)

Note: This feature Requires Knox Standard SDK version 5.0.

34. Control data saver android settings of the device

!#suremdm
allowDataSaving(true/false)

35. Remove website shortcuts on device through SureMDM

!#suremdm
DeleteAppShortcut(PackageName,ClassName,URL,Name)

36. Stop SureMDM Agent as a Foreground Service

!#suremdm
stopNixFromForeGround

37. Enable analytics of SureLock/SureVideo/SureFox

!#suremdm
EnableAnalytics(com.gears42.surelock,043e370a)

38. Control power saver mode android settings of the device

!#suremdm
disablePowerSavingMode(true/false)

Note: Available for devices with KNOX.

39. Disable Multi Window View on Samsung Knox devices

!#suremdm
allowMultiWindowMode(false)

Note: Available for devices with KNOX.

40. Enable Multi Window View on Samsung Knox devices

!#suremdm
allowMultiWindowMode(true)

Note: Available for devices with KNOX.

41. Enable/Disable battery optimization for any third party applications

!#suremdm
addAppToBatteryOptimization (packageName1,…,packageNameN)

42. Block uninstallation of apps in Dedicated Devices (formerly called COSU or Corporate-Owned Single-Use)

!#suremdm
blockAppUninstallation(packageid)

43. Unblock uninstallation of apps in Dedicated Devices 

!#suremdm
unblockAppUninstallation(packageid)

44. Change SureMDM Agent Service Restart Time

!#suremdm
NixServiceRestartTime(TimeInMinutes)

45. Delete Google account

!#suremdm
removeAccountFromDevice(account type)

Note: Available for devices with Knox and EA System Plugin App.Works in Device Admin and Device Owner Enrollments.

46. Remove Gmail account from Email App

!#suremdm
removeAccountFromDevice(package name for Email app)

Note: Available for devices with Knox and EA System Plugin App.Works in Device Admin and Device Owner Enrollments.

47. Wake up the screen

!#suremdm
screen(ON/OFF)

48. Turn bluetooth on and off

!#suremdm
Bluetooth(on\off)

49. Set System name script (the name you see in the Blutooth setting / About)

!#suremdm
SetBTDeviceName(name)

Note: Available for devices with Device Admin Enrollment and Signed Enterprise Agent.

50. Launch Package RunScript (by Package and App Name)

!#suremdm
 launch(package/appName)

51. Run scripts when SureMDM Agent services are disabled

!#suremdmoffline (script)

52. Prefer Mobile Data

!#suremdm
 preferMobileData(true/false)

Note: Available for Android devices with Android Lollipop and above.

53. Delete file from external SD Card for older than specified days

!#suremdm
 deleteFromSDcard(path,days)

Note: Available for Android devices with Android Lollipop and above.

54. Block uninstallation of application in Dedicated Devices

 !#suremdm
 blockAppUninstallation(packageid)

Note: Available for Android devices with Android Lollipop and above.

55. Unblock uninstallation of application in Dedicated Devices

!#suremdm
 unblockAppUninstallation(packageid)

Note: Available for Android devices with Android Lollipop and above.

56. Use Lollipop screen capture

!#suremdm
 LollipopScreenCapture(true)

Note: Available for Android devices with Android Lollipop and above.

57. Change the language

 !#suremdm
 changeDeviceLanguage(fr)

Note: Available for devices Enrolled with Device Admin Jelly Bean OS. For Kitkat and above OS, requires EA and Knox devices running API level 17 and above.

58. Reboot device

!#suremdm
reboot

Note: Available for devices with Signed Enterprise Agent.

59. Install test application

!#suremdm
install(/sdcard/file name)

Note: Available for devices with Signed Enterprise Agent.

60. Uninstall application

!#suremdm
uninstall(package name)

Note: Available for devices with Signed Enterprise Agent.

61. Turn GPS ON/OFF

!#suremdm TurnOnGPS(FALSE)

Note: Available for devices with Signed Enterprise Agent.

62. Disable Third Party App Administrator

!#suremdm
deactivateadmin(com.xyz)

Note: Available for devices with Signed Enterprise Agent.

63. Create APN Settings

!!#suremdm
createApnSettings
(apnname,user,password,server,mmsc,mmsproxy,mmsport,mcc,mnc,type,name, setdefaultValue)

Note: Available for devices with Signed Enterprise Agent.

64. Set Time ,Date and Time Zone

!#suremdm
SetDateTime
(DD-MM-YYYY,00:00:00AM/PM,Continent/State)

Note: Available for devices with Signed Enterprise Agent.

65. Set screen off timeout

!#suremdm
screenofftimeout(60)

Note: Available for devices with Signed Enterprise Agent.

66. Delete APN Settings

!#suremdm
deleteApnSettings(APN_name)

Note: Available for devices with Signed Enterprise Agent.

67. Change Bluetooth name of device

!#suremdm
SetBTDeviceName(name)

68. Changed device bluetooth name to serial number in device grid

Note: Available for all Android devices.

!#suremdm
SetBTDeviceName(1234567890)

69. Allow and deny runtime permissions

!#suremdm
allowRuntimePermissions(true/false,packagename)

Note: Available for devices with KNOX and Signed Enterprise Agent.

70. Change the Date format

!#suremdm
putSystemSettings(date_format,dd/MM/yyyy)

Note: Available for devices Signed Enterprise Agent.

71. Disable Admin of Any App if device is signed:

!#suremdm
deactivateadmin(com.xyz)

72. Turn GPS ON/OFF

!#suremdm
TurnOnGPS(FALSE)

73. Enable app by package name

!#suremdm
enable(pkg1,pkg2..pkN)

Note: Available for devices with KNOX.

74. Disable app by package name To disable app by package name

!#suremdm
disable(pkg1,pkg2..pkN)

Note: Available for devices with KNOX.

75. Force stop an app

!#suremdm
StopApp(package1,package2,..,packageN)

Note: Available for devices with KNOX.

76. Enable SureLock Multi User Analytics settings from SureMDM Console

!#suremdm
EnableMultiUserAnalytics(com.gears42.surelock,<secretkey>)
Was this helpful?
YesNo
Updated on October 2022