Aller au contenu

Android Shell Scripting with SureMDM

Sep 27, 2013 | 42Gears Team

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 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 Nix Settings

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

22. Apply Nix 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 Nix Service

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

27. Start Nix Service

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

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 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. Get Device Name

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

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 com.nix

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 com.nix

33. Start Nix

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

34. Set Device Name

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

35. Set Polling Type

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

36. Set Periodic Polling Interval in Minutes

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

37. Use Secure Protocol

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

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

40. Clear App Data

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

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

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" com.gears42.surefox

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 com.gears42.system.eaplugin

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 com.nix

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

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

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

51. 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/Rooted.

3. Turn ON GPS Status

!#suremdm 
TurnOnGPS(true,N)   

N value can be:

  • 0 = LOCATION_MODE_OFF
  • 1 = LOCATION_MODE_SENSORS_ONLY
  • 2 = LOCATION_MODE_BATTERY_SAVING
  • 3 = LOCATION_MODE_HIGH_ACCURACY
  • *Note: It prompts the user to enable GPS on the devices that are non-Knox/Platform signed/Rooted.

    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 Nix app from Battery optimization

    !#suremdm
    forceIgnoreBatteryOptimizaion(TRUE)

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

    !#suremdm
    activateadmin(com.gears42.nixsam)

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

    !#suremdm
    forceIgnoreBatteryOptimization(true/false)

    19. Change Nix 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

    31. Apply a restriction from creating users

    !#suremdm
    allowUserCreation(false/true)

    32. Block notifications on lock screen Except Nix

    !#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 Nix 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)

    39. Disable Multi Window View on Samsung Knox devices

    !#suremdm
    allowMultiWindowMode(false)

    40. Enable Multi Window View on Samsung Knox devices

    !#suremdm
    allowMultiWindowMode(true)

    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 Nix Service Restart Time

    !#suremdm
    NixServiceRestartTime(TimeInMinutes)

    45. Delete Google account

    !#suremdm
    removeAccountFromDevice(account type)

    46. Remove Gmail account from Email App

    !#suremdm
    removeAccountFromDevice(package name for Email app)

    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)

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

    !#suremdm
     launch(package/appName)

    51. Run scripts when nix 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)

    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,packagename)

    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)

    75. Enable SureLock Multi User Analytics settings from SureMDM Console

    !#suremdm
    EnableMultiUserAnalytics(com.gears42.surelock,<secretkey>)
    Signup for SureMDM Free Trial

    Subscribe for our free newsletter

    Thank you! you are successfully subscribed.
    newsletter

    Exclusive News and Updates on Enterprise Mobility!

    * I consent to receive newsletters via email from 42Gears and its Affiliates.
    Please agree
    * I have reviewed and agreed to 42Gears Privacy Policy and Terms of Use prior to subscribing and understand that I may change my preference or unsubscribe at any time.
    Please agree
    Please verify captcha
    Please enter a valid official email