Pushing scripts to cellphone

Who uses scripts to monitor servers, mostly home ones, should not see much advantage paying for some sms based alert solution, for example when a download is finished or when the system is dangerously running  out of a resource.

In the other side, it is really nice to be warned instead of have to poll for this kind of information. This is motivation enough to search for alternative solutions.

In this article will be described how to monitor the available disk space in a file server and send to the administrator’s mobile a message every time the system reaches a certain threshold in disk space.

In order to do this we will use a Linux server, that will act as our file server and the software Pushbullet, that will be responsible for receiving the notitications.

Mainly, access Pushbullet’s web site, create an account and install the mobile application (available for Android and IOS).

After that, just go into their site and find out an access token to the cellphone which will receive the message ( it is a code that looks like this:bxrj46KOnhAmgen2ZMG2jnr47onwPUbH ).

In order to send the message, in the server, we will install a software called Curl. If your distro did not install by default, install it.

The following script is used to monitor the drive’s disk space and sends a message every time the occupied space reaches more than 90%, described in the ‘threshhold’ variable ( using the output of the command ‘df -H’ and capturing the line corresponding a selected hard-drive. This must be adapted to fit another server, this is not hard to do ).

#Maximum disk usage in percent. Beyond this, send a message. 
df -H | grep -vE '^Filesystem|tmpfs|cdrom|none|udev|shm|cgroup' | awk '{ print $5 " " $1 " " $4}' | while read OUTPUT; 
  USEP=$(echo $OUTPUT | awk '{ print $1}' | cut -d'%' -f1  ) 
  DSK_FREE=$(echo $OUTPUT | awk '{ print $3}' ) 
  PARTITION=$(echo $OUTPUT | awk '{ print $2 }' ) 
  if [ $USEP -ge $THRESHOLD ]; then 
    MESSAGE="Running out of space on \"$PARTITION \". Only  $DSK_FREE left on device." 

    <run send to phone script> "$MESSAGE"   


The following script sends a message to any cellphone that has the access key stored in the variable called “API”.

#This script receives a message as a parâmeter and sends to a push bullet enabled device. 
#Device unique id, available on your pushbullet account. 
curl -u $API: https://api.pushbullet.com/v2/pushes -d type=note -d title="Alert" -d body="$MSG"

Here is a sample showing how this message reaches the device: