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.

runscript-flow

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 Nix

am start -n com.nix/.MainFrm

19. Exit SureLock

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

20. Exit Surefox

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

21. Apply Nix Settings

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

22. Apply Nix Settings

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

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%

24. Change Polling mechanism to Normal polling

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

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%

26. To Stop Nix Service

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

27. Start Nix Service

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

28. Script to change Nix Settings Password

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

29. Script with password authentication

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

30. Get Device Name

am broadcast -a com.nix.COMMUNICATOR -e command get_device_name

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

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

33. Start Nix

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

34. Set Device Name

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

35. Set Polling Type

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

36. Set Periodic Polling Interval in Minutes

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

37. Use Secure Protocol

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

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

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

40. Clear App Data

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

Note: Available for devices with Signed Enterprise Agent.

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

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

42. 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"

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

43. Forget the network

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

44. Reboot device

su -c reboot

45. Install test application

su -c pm install /sdcard/test.apk

46. Uninstall application

su -c pm uninstall com.example.MyApp

47. Clear App Data

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

 

List of Custom SureMDM Scripts:

1. Change time zone

!#suremdm
SetTimeZone(Continent/country)

2. Turn GPS ON

!#suremdm
TurnOnGPS(true)

3. Change Device’s Screen Brightness

!#suremdm
SetScreenBrightness(0, 255)

4. Enable Logger

!#suremdm
enableLogger

5. Disable Logger

!#suremdm
disableLogger

6. Run Script in Sync

!#suremdm 
RunScriptsInSync(TRUE)

7. Scale Down Clicks

!#suremdm
RunScriptsInSync(TRUE)

8. Kill Process

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

9. Sleep

!#suremdm
sleep(100)

10. Keep CPU On

!#suremdm
KeepCPUOn(TRUE)

11. Copy text to clipboard

!#suremdm
copyToClipboard(text)

12. RunScript to clear clipboard

!#suremdm
clearClipboard()

13. Make device screen on when remote screen is running

!#suremdm
RemoteScreenDeviceSleep(FALSE)

14. Launch app by package name or app name

!#suremdm
launch(package/appName)

15. Ignore Nix app from Battery optimization

!#suremdm
forceIgnoreBatteryOptimizaion(TRUE)

16. Activate admin of SureMDM Nix Samsung Verison on Device:

!#suremdm
activateadmin(com.gears42.nixsam)

17. Ignore Nix app from Battery optimization with true/false

!#suremdm
forceIgnoreBatteryOptimization(true/false)

18. Change Nix Service Restart Time

!#suremdm
NixServiceRestartTime(TimeInMinutes)

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

!#suremdm
screen(ON/OFF)

20. Turn bluetooth On/Off on the device

!#suremdm
Bluetooth(on\off)

21. Wrong security type

!#suremdm
setMinimumWifiSecurity(WPA)

22. Connect to open network

!#suremdm
setMinimumWifiSecurity(open)

23. Connect to WPA network

!#suremdm
setMinimumWifiSecurity(wpa)

24. 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)

25. Disable Close button

!#suremdm
DisableCloseButton(true)

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

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

27. Delete SMS

 !#suremdm
delete(sms)

28. Unlock an application:

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

29. Remove all users from device for Samsung devices

!#suremdm
removeAllUsersFromDevice

30. Apply a restriction from creating users

!#suremdm
allowUserCreation(false/true)

31. Block notifications on lock screen Except Nix

!#suremdm
blockLockScreenNotifications(true)

*Note: This feature Requires Knox Standard SDK version 5.0.

32. Show the notification on Lock Screen

!#suremdm
blockLockScreenNotifications(false)

*Note: This feature Requires Knox Standard SDK version 5.0.

33. Control data saver android settings of the device

!#suremdm
allowDataSaving(true/false)

34. Remove website shortcuts on device through SureMDM

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

35. Stop SureMDM Nix as a Foreground Service

!#suremdm
stopNixFromForeGround

36. Enable analytics of SureLock/SureVideo/SureFox

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

37. Control power saver mode android settings of the device

!#suremdm
disablePowerSavingMode(true/false)

38. Disable Multi Window View on Samsung Knox devices

!#suremdm
allowMultiWindowMode(false)

39. Enable Multi Window View on Samsung Knox devices

!#suremdm
allowMultiWindowMode(true)

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

!#suremdm
addAppToBatteryOptimization (packageName1,…,packageNameN)

41. Block uninstallation of apps in COSU

!#suremdm
blockAppUninstallation(packageid)

42. Unblock uninstallation of apps in COSU

!#suremdm
unblockAppUninstallation(packageid)

43. Change Nix Service Restart Time

!#suremdm
NixServiceRestartTime(TimeInMinutes)

44. Delete Google account

!#suremdm
removeAccountFromDevice(account type)

45. Remove Gmail account from Email App

!#suremdm
removeAccountFromDevice(package name for Email app)

46. Wake up the screen

!#suremdm
screen(ON/OFF)

47. Turn bluetooth on and off

!#suremdm
Bluetooth(on\off)

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

!#suremdm
SetBTDeviceName(name)

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

!#suremdm
 launch(package/appName)

50. Run scripts when nix services are disabled

!#suremdmoffline (script)

51. Prefer Mobile Data

!#suremdm
 preferMobileData(true/false)

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

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

53. Block uninstallation of application in COSU device

 !#suremdm
 blockAppUninstallation(packageid)

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

54. Unblock uninstallation of application in COSU device

!#suremdm
 unblockAppUninstallation(packageid)

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

55. Use Lollipop screen capture

!#suremdm
 LollipopScreenCapture(true)

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

56. Change the language

 !#suremdm
 changeDeviceLanguage(fr)

*Note: Available for Android Jellybean signed devices and for all devices below Android Jellybean.

57. Reboot device

!#suremdm
reboot

*Note: Available for devices with Signed Enterprise Agent.

58. Install test application

!#suremdm
install(/sdcard/file name)

*Note: Available for devices with Signed Enterprise Agent.

59. Uninstall application

!#suremdm
uninstall(package name)

*Note: Available for devices with Signed Enterprise Agent.

60. Turn GPS ON/OFF

!#suremdm TurnOnGPS(FALSE)

*Note: Available for devices with Signed Enterprise Agent.

61. Disable Third Party App Administrator

!#suremdm
deactivateadmin(com.xyz)

*Note: Available for devices with Signed Enterprise Agent.

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

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

64. Set screen off timeout

!#suremdm
screenofftimeout(60)

*Note: Available for devices with Signed Enterprise Agent.

65. Delete APN Settings

!#suremdm
deleteApnSettings(APN_name)

*Note: Available for devices with Signed Enterprise Agent.

66. Change Bluetooth name of device

!#suremdm
SetBTDeviceName(name)

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

 !#suremdm
SetBTDeviceName(1234567890)

68. Allow and deny runtime permissions

 !#suremdm
allowRuntimePermissions(true/false)

69. Change the Date format

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

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

 !#suremdm
deactivateadmin(com.xyz)

71. Turn GPS ON/OFF

!#suremdm
TurnOnGPS(FALSE)

72. Enable app by package name

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

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

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

74. Force stop an app

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

 

Signup for SureMDM Free Trial
 

Leave a Comment