Posted By

2mf on 11/06/12


Tagged

crontab cron whois


Versions (?)

Whois crontab monitor


 / Published in: Bash
 

Simple whois monitor by text file DB. Compares filesizes to exclude unimportant difference like current date in output.

  1. #!/bin/sh
  2. # Copyright (c) 2010 Mihail Fedorov, http://mihailfedorov.ru
  3. # $ ./whois2.sh
  4.  
  5. # DB file format:
  6. # domain.ru|whois.ripn.net|[email protected]|
  7. # domain.tel|whois.nic.tel|[email protected]|
  8.  
  9. # change this
  10. WORKDIR="/home/kolo/bots/whois"
  11. FILE="/home/kolo/bots/whois.db.txt"
  12. FS="|"
  13. # thanks
  14.  
  15. while read line
  16. do
  17. # warZ
  18. DOMAIN=$(echo $line|cut -d$FS -f1)
  19. SERVER=$(echo $line|cut -d$FS -f2)
  20. MAIL=$(echo $line|cut -d$FS -f3)
  21.  
  22. TEXTBEFORE="/home/kolo/bots/before.txt"
  23. TEXTAFTER="/home/kolo/bots/after.txt"
  24.  
  25. NEWFILE="$WORKDIR/$DOMAIN.$SERVER.$MAIL"
  26. OLDFILE="$WORKDIR/$DOMAIN.$SERVER.$MAIL.old"
  27. touch $NEWFILE
  28.  
  29. mv $NEWFILE $OLDFILE 2> /dev/null
  30. whois -H -h $SERVER $DOMAIN > $NEWFILE 2> /dev/null
  31.  
  32. oldsize=$(stat -c %s "$OLDFILE" 2> /dev/null)
  33. newsize=$(stat -c %s "$NEWFILE")
  34.  
  35. if [ "$oldsize" != "$newsize" ] && [ -s $NEWFILE ] ; then
  36. cat $TEXTBEFORE $OLDFILE $TEXTAFTER $NEWFILE > /tmp/whois.txt
  37. cat /tmp/whois.txt | mail -s "[Whois2] $DOMAIN updated" $MAIL
  38. # here comes also notifying via Nabaztag API.
  39. # you don't need this ;)
  40. # but you can add SMS/Jabber/ICQ
  41. else
  42. mv $OLDFILE $NEWFILE 2> /dev/null
  43. fi
  44. done < $FILE

Report this snippet  

You need to login to post a comment.