#!/bin/bash # # Script Initiates Shutdown Sequence for reboot twitter # # Config Var's USER=linuxblog # This is the startup of the reboot script and initiates the reboot reboot() { # Set the date variables DATEDOWN=$(date +%c); SECSDOWN=$(date +%s); # Echo the going down times echo "Going Down: $DATEDOWN" echo "UNIX TIMESTAMP: $SECSDOWN"; # Write the vars to file echo $VAR","$DATEDOWN","$SECSDOWN > /home/$USER/bin/rebootdata.txt # Issue Reboot command /usr/bin/reboot; } # This is what happens once bashrc is logged in back() { # if the reboot data file has more than one line, lets do this if [ $(wc -l /home/$USER/bin/rebootdata.txt | cut -c 1) -ge 1 ]; then TYPE=$(cat /home/$USER/bin/rebootdata.txt | cut -d , -f 1) DATEDOWN=$(cat /home/$USER/bin/rebootdata.txt | cut -d , -f 2) SECSDOWN=$(cat /home/$USER/bin/rebootdata.txt | cut -d , -f 3) DATENOW=$(date +%c); SECSNOW=$(date +%s); TD=$((SECSNOW - SECSDOWN)); #LOG RESULTS TO FILE echo "DOWNED: $DATEDOWN" > /home/$USER/.downed; echo "BACKUP: $DATENOW" >> /home/$USER/.downed; echo "TOTALD: $TD Seconds" >> /home/$USER/.downed; #TIME PART if [ $(echo $TYPE) -eq 1 ]; then cat /home/$USER/.downed fi #FOR TTIME PART if [ $(echo $TYPE) -eq 2 ]; then cat /home/$USER/.downed curl -u twitteruser:twitterpass -s -F status="$(cat /home/$USER/.downed)" http://twitter.com/statuses/update.xml http://twitter.com/account/end_session 2> /dev/null > /dev/null echo "Posted to Twitter!" fi #CLEANUP VARS HERE rm /home/$USER/.downed unset DATEDOWN unset DATENOW unset TD unset SECSNOW unset SECSDOWN unset TYPE fi } case "$1" in back) back ;; time) VAR=1; reboot ;; ttime) VAR=2; reboot ;; *) echo $"Usage: $0 {time|ttime|back}" exit 1 esac