Advertisement
big_bum

Twitter send SMS if autentification fail

May 6th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.70 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7.  
  8. # Copyright (C) 2012 by +Mitesh Shah
  9. # Mr.Miteshah@gmail.com
  10. # People who works on this script to make it easier and good
  11. # +Chris Raess +Josh Sabboth and +Christopher Timm
  12. # People who want to use this script in their Mac OS X
  13. # Read the +Israel Torres comments on this post
  14. #https://plus.google.com/111560558537332305125/posts/S6mrHJeS5Wd
  15.  
  16.  
  17. # Checking every hour for any Authentication Failure entry founded on
  18. # /var/log/auth.log file and update twitter status
  19.  
  20. # You should need to create a crontab entry for this script
  21. # So this script runs every hours automatically
  22.  
  23. #Checking twidge (command-line twitter client) is installed or not
  24. dpkg --list | grep twidge &> /dev/null
  25.  
  26. if [ $? -ne 0 ]
  27. then
  28. echo "Twidge (command-line twitter client) is not installed :("
  29. echo "For how to install and configure twidge check the following links:"
  30. echo "http://www.howtogeek.com/62018/how-to-use-the-linux-terminal-to-update-twitter/"
  31. else
  32. #Calculate 1 hour ago time in unix time format
  33. HOURAGO=$(date +%s --date "1 hour ago")
  34.  
  35. # Take the last authentication failure entry from auth.log
  36. SMS=$(cat /var/log/auth.log | grep 'authentication failure' | tail -n1 )
  37.  
  38. # Extract the time from SMS variable and convert it to unix time format
  39. SMSTIME=$(date -d "$(echo $SMS | awk '{print $1,$2,$3}')" +%s)
  40.  
  41. if [ $SMSTIME -gt $HOURAGO ]; then
  42. echo "Updating Twitter Status..."
  43. echo $SMS | awk '{print $3,$5,$9,$10,$12,$14,$15,$16}' | twidge update
  44. fi
  45. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement