Example: show device status

Download the following file to your PC, then upload it to remote.it:

 Get-Pi-Status.sh

This script returns the following info into status columns A through E:

  • Operating System name

  • Linux Version (uname -a command)

  • Uptime (time since last reboot)

  • Number of installed remote.it Services

  • Version of of the installed connectd or remoteit package

 

If you are on Windows, editing this file in Notepad will cause issues because the line feeds are not compatible with your Pi's Linux OS. We suggest you use a Linux compatible text editor for Windows such as Notepad++.

The NOTIFIER script

In the script, the file represented by the NOTIFIER variable is used to report various interesting bits of info about your systems back to our servers. For example:

  • Script completed successfully
  • Script completed, but with errors
  • Writing information to Status Columns A through E

You must call the NOTIFIER script from your own script, no matter how simple your script is.  The NOTIFIER script is installed when you install the remoteit or connectd packages.  

Detecting the operating system and package

Since different packages put the NOTIFIER script in different places or call it something different, there is a section of code which looks for files in standard locations to determine which package is installed. The code below allows compatibility going back to our earliest packages which supported bulk scripting.

# look for remoteit 4.x
if [ -e /usr/share/remoteit/task_notify.sh ]; then
TOOL_DIR="/usr/share/remoteit"
NOTIFIER=task_notify.sh
package=remoteit
logger "remoteit package found."
cversion=$(cat ${TOOL_DIR}/version.txt)
# look for weavedconnectd package notifier
elif [ -e /usr/bin/task_notify.sh ]; then
NOTIFIER=task_notify.sh
TOOL_DIR="/usr/bin"
package=weavedconnectd
# get the package version of whichever package is installed
cversion=$(dpkg -s $package | grep Version)
logger "Weaved package found."
# need to account for possibly remoteit installed over connectd
# so check for remoteit first.
elif [ -f /usr/bin/connectd_task_notify ]; then
TOOL_DIR="/usr/bin"
dpkg -s remoteit
if [ $? -eq 0 ]; then
NOTIFIER=connectd_task_notify
package=remoteit
# get the package version of whichever package is installed
cversion=$(dpkg -s $package | grep Version)
logger "remoteit status script"
else
dpkg -s remoteit-desktop
if [ $? -eq 0 ]; then
NOTIFIER=connectd_task_notify
package=remoteit-desktop
# get the package version of whichever package is installed
cversion=$(dpkg -s $package | grep Version)
logger "remoteit-desktop status script"
else
dpkg -s connectd
if [ $? -eq 0 ]; then
NOTIFIER=connectd_task_notify
package=connectd
# get the package version of whichever package is installed
cversion=$(dpkg -s $package | grep Version)
logger "connectd status script"
else
logger "remoteit $0 error - couldn't identify package"
# There is no point in calling the NOTIFIER, since we couldn't find it.
# ret=$(${TOOL_DIR}/$NOTIFIER 2 $1 $2 "Couldn't identify package")
exit 1
fi
fi
fi
fi

The variables TOOL_DIR and NOTIFIER are set here used to point at the actual NOTIFIER script on your system so that it can be called when needed.

TOOL_DIR="/usr/bin" 
NOTIFIER="connectd_task_notify"

If you know that your devices are only using remoteit 4.x and later, you can simplify this to:

 

# look for remoteit 4.x
if [ -e /usr/share/remoteit/task_notify.sh ]; then
TOOL_DIR="/usr/share/remoteit"
NOTIFIER=task_notify.sh
package=remoteit
logger "remoteit package found."
cversion=$(cat ${TOOL_DIR}/version.txt)
fi

For example, the OS Name is reported in Status column A. Parameter 1 = a.

# Update status column A (StatusA) in remote.it portal
#-------------------------------------------------
# retrieve the os ID as reported by the command “cat /etc/os-release”
os=$(cat /etc/os-release | grep -w ID | awk -F "=" '{print $2 }')
# send to status column a in remot3.it portal
ret=$(${TOOL_DIR}/$NOTIFIER a $1 $2 $os)
The call shown below to the $NOTIFIER script with parameter1 = 1 is used to indicate successful execution of the script.  This script does not have any failure exit codes, but those could be added depending on what you are doing.
#---- You MUST use the final line:
ret=$(${TOOL_DIR}/$NOTIFIER 1 $1 $2 "Job complete")
It may take several minutes for the Job Status to fully update and clear, even after running a script which by itself completes rapidly.
========
Was this article helpful?
0 out of 0 found this helpful