From bba281c7ebd1a9f871f2db27da851b36e7680445 Mon Sep 17 00:00:00 2001 From: Seth Parrish Date: Thu, 2 Mar 2017 14:24:46 -0500 Subject: [PATCH] Added comments & reboot modification Added comments to help new users configuring the script for their own machine. Also, changes reboot command to "init 6" because reboot does not work on all Linux systems. --- README.md | 76 ++++++++++++++-------------- iftttcontrol.sh | 66 +++++++++++++----------- iftttcontrolnotify.sh | 113 +++++++++++++++++++++++------------------- 3 files changed, 139 insertions(+), 116 deletions(-) diff --git a/README.md b/README.md index 9704b0c..45ac241 100755 --- a/README.md +++ b/README.md @@ -1,39 +1,39 @@ -IFTTT-Remote-Control -==================== - -Run preset commands on a linux computer via text message - -###Introduction### - -This project works thanks to [IFTTT](https://ifttt.com) and [Dropbox](https://www.dropbox.com). IFTTT receives a text and syncs it to the computer via Dropbox. Then a script will check for the existence of the file and if it is there, run a command. - -###Implementation### - -####Dropbox#### - -1. You will need to create an account if you haven't already. -2. Dropbox can be downloaded from [https://www.dropbox.com/install](https://www.dropbox.com/install) -3. See the [Dropbox Wiki](http://www.dropboxwiki.com/Text_Based_Linux_Install#Running_on_system_startup) for configuring Dropbox to run at startup - -####IFTTT#### - -1. Create an account if you haven't already -2. Go to [https://ifttt.com/recipes/85666](https://ifttt.com/recipes/85666) activate the Dropbox and SMS channels if they aren't already, customize as needed, then click "Use Recipe" - -####Script#### - -1. Download the script ```iftttcontrol.sh``` from this repository -2. Edit the variables at the beginning of the file for the IFTTT folder location and where you want a log to be stored -3. Edit the command variables if you are using different IFTTT text tags -4. You may want to move the script to a safe location and change the owner to root so it can't be edited too easily - -####Cron#### - -1. Since commands such as ```shutdown``` require root, I used the crontab at /etc/crontab to do so -2. This is the line that I entered in crontab to run the script every minute, where "```/etc/ifttt/iftttcontrol.sh```" is the location of the script, it may be different for you: -```*/1 * * * * root sh /etc/ifttt/iftttcontrol.sh``` - -###Pushover Notifications### - -If you would like to receive [Pushover](https://pushover.net) notifications, use the iftttcontrolnotify.sh file instead of the iftttcontrol.sh file. +IFTTT-Remote-Control +==================== + +Run preset commands on a linux computer via text message + +###Introduction### + +This project works thanks to [IFTTT](https://ifttt.com) and [Dropbox](https://www.dropbox.com). IFTTT receives a text and syncs it to the computer via Dropbox. Then a script will check for the existence of the file and if it is there, run a command. + +###Implementation### + +####Dropbox#### + +1. You will need to create an account if you haven't already. +2. Dropbox can be downloaded from [https://www.dropbox.com/install](https://www.dropbox.com/install) +3. See the [Dropbox Wiki](http://www.dropboxwiki.com/Text_Based_Linux_Install#Running_on_system_startup) for configuring Dropbox to run at startup + +####IFTTT#### + +1. Create an account if you haven't already +2. Go to [https://ifttt.com/recipes/85666](https://ifttt.com/recipes/85666) activate the Dropbox and SMS channels if they aren't already, customize as needed, then click "Use Recipe" + +####Script#### + +1. Download the script ```iftttcontrol.sh``` from this repository +2. Edit the variables at the beginning of the file for the IFTTT folder location and where you want a log to be stored +3. Edit the command variables if you are using your own IFTTT text tags +4. You may want to move the script to a safe location and change the owner to root so it can't be edited too easily + +####Cron#### + +1. Since commands such as ```shutdown``` require root, I used the crontab at /etc/crontab to do so +2. This is the line that I entered in crontab to run the script every minute, where "```/etc/ifttt/iftttcontrol.sh```" is the location of the script, it may be different for you: +```*/1 * * * * root sh /etc/ifttt/iftttcontrol.sh``` + +###Pushover Notifications### + +If you would like to receive [Pushover](https://pushover.net) notifications, use the iftttcontrolnotify.sh file instead of the iftttcontrol.sh file. Be sure to set the POTOKEN and POUSER variables. \ No newline at end of file diff --git a/iftttcontrol.sh b/iftttcontrol.sh index f73ff1a..713a559 100755 --- a/iftttcontrol.sh +++ b/iftttcontrol.sh @@ -1,29 +1,39 @@ -#!/bin/sh -#This script checks for a Dropbox-synced file and then runs a preconfigured command accordingly - -IFTTTLOCATION="/home/username/Dropbox/IFTTT" -LOGLOCATION="/home/username/IFTTT.log" -SLEEP="sleep" -REBOOT="reboot" -SHUTDOWN="shutdown" -Date=$(date +"%Y-%m-%d %T") - -if [ -e $IFTTTLOCATION/$SLEEP.txt ]; then -rm $IFTTTLOCATION/$SLEEP.txt -echo "$Date - Going to sleep" >> $LOGLOCATION -pm-suspend -exit 0 -fi -if [ -e $IFTTTLOCATION/$REBOOT.txt ]; then -rm $IFTTTLOCATION/$REBOOT.txt -echo "$Date - Rebooting" >> $LOGLOCATION -reboot -exit 0 -fi -if [ -e $IFTTTLOCATION/$SHUTDOWN.txt ]; then -rm $IFTTTLOCATION/$SHUTDOWN.txt -echo "$Date - Shutting down" >> $LOGLOCATION -shutdown now -exit 0 -fi +#!/bin/sh +#This script checks for a Dropbox-synced file and then runs a preconfigured command accordingly + +#Dropbox folder and log lcoation of choosing +IFTTTLOCATION="/home/username/Dropbox/IFTTT" +LOGLOCATION="/home/username/IFTTT.log" +Date=$(date +"%Y-%m-%d %T") + +#Add custom variables here to trigger custom commands +SLEEP="sleep" +REBOOT="reboot" +SHUTDOWN="shutdown" + +#Sleep +if [ -e $IFTTTLOCATION/$SLEEP.txt ]; then +rm $IFTTTLOCATION/$SLEEP.txt +echo "$Date - Going to sleep" >> $LOGLOCATION +pm-suspend +exit 0 +fi + +#Reboot +if [ -e $IFTTTLOCATION/$REBOOT.txt ]; then +rm $IFTTTLOCATION/$REBOOT.txt +echo "$Date - Rebooting" >> $LOGLOCATION +init 6 +exit 0 +fi + +#Shutdown +if [ -e $IFTTTLOCATION/$SHUTDOWN.txt ]; then +rm $IFTTTLOCATION/$SHUTDOWN.txt +echo "$Date - Shutting down" >> $LOGLOCATION +shutdown now +exit 0 +fi + +#Add custom commands here following example formatting exit 0 \ No newline at end of file diff --git a/iftttcontrolnotify.sh b/iftttcontrolnotify.sh index 9070367..3e8c62d 100755 --- a/iftttcontrolnotify.sh +++ b/iftttcontrolnotify.sh @@ -1,51 +1,64 @@ -#/bin/sh -#This script checks for a Dropbox-synced file and then runs a preconfigured command accordingly -#It also sends a notification to your devices via Pushover (pushover.net) - -IFTTTLOCATION="/home/username/Dropbox/IFTTT" -LOGLOCATION="/home/username/IFTTT.log" -SLEEP="sleep" -REBOOT="reboot" -SHUTDOWN="shutdown" -POTOKEN="000000000000" -POUSER="000000000000" -POSOUND="intermission" -Date=$(date +"%Y-%m-%d %T") - -if [ -e $IFTTTLOCATION/$SLEEP.txt ]; then -rm $IFTTTLOCATION/$SLEEP.txt -curl -s \ --F "token=$POTOKEN" \ --F "user=$POUSER" \ --F "message=Sleeping at $Date" \ --F "sound=$POSOUND" \ -https://api.pushover.net/1/messages.json -echo "$Date - Going to sleep" >> $LOGLOCATION -pm-suspend -exit 0 -fi -if [ -e $IFTTTLOCATION/$REBOOT.txt ]; then -rm $IFTTTLOCATION/$REBOOT.txt -curl -s \ --F "token=$POTOKEN" \ --F "user=$POUSER" \ --F "message=Rebooting at $Date" \ --F "sound=$POSOUND" \ -https://api.pushover.net/1/messages.json -echo "$Date - Rebooting" >> $LOGLOCATION -reboot -exit 0 -fi -if [ -e $IFTTTLOCATION/$SHUTDOWN.txt ]; then -rm $IFTTTLOCATION/$SHUTDOWN.txt -curl -s \ --F "token=$POTOKEN" \ --F "user=$POUSER" \ --F "message=Shutting down at $Date" \ --F "sound=$POSOUND" \ -https://api.pushover.net/1/messages.json -echo "$Date - Shutting down" >> $LOGLOCATION -shutdown now -exit 0 -fi +#/bin/sh +#This script checks for a Dropbox-synced file and then runs a preconfigured command accordingly +#It also sends a notification to your devices via Pushover (pushover.net) + +#Dropbox folder and log lcoation of choosing +IFTTTLOCATION="/home/username/Dropbox/IFTTT" +LOGLOCATION="/home/username/IFTTT.log" +Date=$(date +"%Y-%m-%d %T") + +#Add custom variables here to trigger custom commands +SLEEP="sleep" +REBOOT="reboot" +SHUTDOWN="shutdown" + +#Pushover configuration +POTOKEN="000000000000" +POUSER="000000000000" +POSOUND="intermission" + +#Sleep +if [ -e $IFTTTLOCATION/$SLEEP.txt ]; then +rm $IFTTTLOCATION/$SLEEP.txt +curl -s \ +-F "token=$POTOKEN" \ +-F "user=$POUSER" \ +-F "message=Sleeping at $Date" \ +-F "sound=$POSOUND" \ +https://api.pushover.net/1/messages.json +echo "$Date - Going to sleep" >> $LOGLOCATION +pm-suspend +exit 0 +fi + +#Reboot +if [ -e $IFTTTLOCATION/$REBOOT.txt ]; then +rm $IFTTTLOCATION/$REBOOT.txt +curl -s \ +-F "token=$POTOKEN" \ +-F "user=$POUSER" \ +-F "message=Rebooting at $Date" \ +-F "sound=$POSOUND" \ +https://api.pushover.net/1/messages.json +echo "$Date - Rebooting" >> $LOGLOCATION +init 6 +exit 0 +fi + +#Shutdown +if [ -e $IFTTTLOCATION/$SHUTDOWN.txt ]; then +rm $IFTTTLOCATION/$SHUTDOWN.txt +curl -s \ +-F "token=$POTOKEN" \ +-F "user=$POUSER" \ +-F "message=Shutting down at $Date" \ +-F "sound=$POSOUND" \ +https://api.pushover.net/1/messages.json +echo "$Date - Shutting down" >> $LOGLOCATION +shutdown now +exit 0 +fi + + +#Add custom commands here following example formatting exit 0 \ No newline at end of file