Creating your own Bulk Script with remote.it (Python)

To create your own Bulk Script with remote.it, you must add one command at the bottom of your script. In this article, we will be creating a Bulk Script in Python.

If you have the connectd or remoteit package installed, add this command to the bottom of your script: 
subprocess.Popen(["/usr/bin/connectd_task_notify", "1", taskID, api, status]).wait()

If you have the weavedconnectd package, add this command to the bottom of your script:

subprocess.Popen(["/usr/bin/task_notify.sh", "a", taskID, api, message]).wait()

You can use this script template to get started:

Template: If you have the connectd or remoteit package installed:

 #!/usr/bin/env python

import sys
import subprocess

taskID = sys.argv[1]
api = sys.argv[2]
notifier_util = "/usr/bin/connectd_task_notify"

#ADD YOUR SCRIPT'S CODE HERE


subprocess.Popen([notifier_util, "1", taskID, api, status]).wait()

Template: If you have the weavedconnectd package:

#!/usr/bin/env python

import sys
import subprocess

taskID = sys.argv[1]
api = sys.argv[2]
notifier_util = "/usr/bin/task_notify.sh"

#ADD YOUR SCRIPT'S CODE HERE


subprocess.Popen([notifier_util, "1", taskID, api, status]).wait()

 

How to make a script cross-compatible with weavedconnectd, connectd and remoteit

If you want to execute a bulk script on devices that have a mix of weavedconnectd, connectd and remoteit packages installed, you can use this template to check for and use the correct notifier script on each device.

Get your script started with the template below: 

#!/usr/bin/env python
# clear_status.py
# clears status columns A through E of the device

import os
import sys
import subprocess

#output to log
sys.stdout = open('pyscriptlog.txt', 'w')
print(sys.argv[1:])

#check connectd installer package
def check_connectd():
if(os.path.isfile("/usr/bin/connectd_task_notify") and os.path.isfile("/usr/bin/task_notify.sh")):
print("target device running both connectd and weavedconnectd")
return("/usr/bin/connectd_task_notify")

elif (os.path.isfile("/usr/bin/connectd_task_notify")):
print("target device running connectd")
return("/usr/bin/connectd_task_notify")

elif(os.path.isfile("/usr/bin/task_notify.sh")):
print("target device running weavedconnectd")
return("/usr/bin/task_notify.sh")

else:
print("ERROR: target device has neither")
exit()

#necessary variables for utilities
finalize_job = "Job Complete"
task_id = sys.argv[1]
api = sys.argv[2]
task_notifier = check_connectd()




#ADD YOUR SCRIPT'S CODE HERE




#tell connectd job is done
subprocess.Popen([task_notifier, "1", task_id, api, finalize_job]).wait()

REMINDER: You can create and run any script that you want! A few uses of Bulk Scripts to achieve tasks like:

  • Automating data retrieval
  • Updating and monitoring devices
  • Application deployment and management
Was this article helpful?
0 out of 0 found this helpful