Android Shell Scripting with SureMDM

Following shell commands can be executed on the devices remotely using SureMDM. You can create a Run Script job in SureMDM and apply to all the devices.

runscript-flow

1. List all files in sdcard

ls /sdcard

2. Create sample folder inside sdcard

mkdir /sdcard/sample

3. Change current directory

cd /sdcard

4. Rename sample.txt to sample1.txt

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

5. Moves folder test1 to test

mv /sdcard/test1 /sdcard/test

6. Delete all files inside test folder with extensions

rm -r /mnt/sdcard/test/*.*

7. Delete all files(even without extenstions) 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. Reboot device (*requires rooting for non-KNOX and non platform-signed devices)

su -c reboot

10. Install test application  (*For silent installation requires rooting for non-KNOX and non platform-signed devices)

su -c pm install /sdcard/test.apk

11. Uninstall application (*For silent installation requires rooting for non-KNOX and non platform-signed devices)

su -c pm uninstall com.example.MyApp

12. Launch specific activity

am start -n com.android.settings/com.android.settings.Settings

13. Launch settings

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

14. Launch Default HomeScreen

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

15. Open google.com in default browser

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

16. Open dialer with phone number

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

17. Make call to 123

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

18. Broadcast fake battery low message

am broadcast -a android.intent.action.BATTERY_LOW

19. Launch Surefox

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

20. Launch SureLock

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

21. Launch Nix

am start -n com.nix/.MainFrm

22. Exit SureLock

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

23. Exit Surefox

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

24. Apply Nix Settings (If Nix Settings on the device is not password protected)

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

25. Apply Nix Settings (If Nix Settings on the device is password protected)

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

26. Change Polling mechanism to periodic polling 

am broadcast -a com.nix.COMMUNICATOR -e command change_nix_settings -e setPollingType 1 -e setPeriodicPollingIntervalInMins 42 -e  password 0000

27. Change Polling mechanism to Normal  polling

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

or

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

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

am broadcast -a   com.nix.COMMUNICATOR  -e command  change_nix_settings -e setDeviceName 1+1 -e setPollingType 1  -e  setPeriodicPollingIntervalInMins  30 -e useSecureProtocol  false -e  password 0000

29. To Stop Nix Service

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

30. To Start Nix Service this script can be applied using other applications or shell console

For JB2 and below devices

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

For others

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

31. Script with password authentication

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

32. Get Device Name

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

33. Apply Settings

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

34. Clear App Data (*requires rooting for non-KNOX and non platform-signed devices)

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

35. Send Messages

am broadcast -a com.nix.COMMUNICATOR -e command send_message -e account_id 1216016 -e subject MySubject -e message MyMessage

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

37. Change Nix Settings

am broadcast -a com.nix.COMMUNICATOR -e command change_nix_settings -e startNix true -e setDeviceName 1+1 -e setPollingType 1 -e setPeriodicPollingIntervalInMins 30 -e useSecureProtocol false

38. Start Nix

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

39. Set Device Name

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

40. Set Polling Type

am broadcast -a com.nix.COMMUNICATOR -e command change_nix_settings -e setPollingType 1

41. Set Periodic Polling Interval in Minutes

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

42. Use Secure Protocol

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

Note: In -e  password 0000, 0000 refers to the Nix Settings password. You can replace 0000 with the current Nix Settings password or skip this part if there is no password set.

43. Change time zone

!#suremdm
SetTimeZone(Asia/Kolkata)

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

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

45. Turn GPS ON/OFF

!#suremdm
TurnOnGPS(false)

Note: Works for signed, KNOX and rooted devices.

!#suremdm
TurnOnGPS(true)

Note: Works for all devices.

46. Change Device’s Screen Brightness

!#suremdm
SetScreenBrightness(value)
value = 0 – 255

47. Turn NFC ON/OFF

!#suremdm
NFCState(value)
value = 0, 1, 2
0 = don't care
1 = always on
2 = always off

Note: Turn NFC ON or OFF works only on KNOX devices.

!#suremdm
NFCState(value)
value = 0, 1, 2
0 = don't care
1 = always on
2 = always off

Note: Turn NFC ON or OFF works only on KNOX devices.

48. Enable Logger

!#suremdm
enableLogger

49. Disable Logger

!#suremdm
disableLogger

50. Set Root Path

!#suremdm
setrootpath(rootpath)

51. Run Script in Sync

!#suremdm
RunScriptsInSync(true)

52. Scale Down Clicks

!#suremdm
RunScriptsInSync(true)

53. Kill Process

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

54. Sleep

!#suremdm
sleep(100) //100 millisec

For SureMDM 30 day free trial, click here For more details about SureMDM, click here

 

Leave a Comment