I have been using this script for a long time (maybe 13 years) with only very slight changes. It was probably one of the first cool ideas I had for a way to track laptops issued to employees that might possibly be stolen. Granted, today, we use full disk encryption and other cool things that almost makes this script obsolete….but in the event something does get stolen, we can always track it.
The script only requires a crontab entry and a way to send mail (I use ssmtp btw).
You often hear about people who have cell phones stolen, laptops, etc and I know there are services that does this….but this is pretty minimal.
Without further wait….here is the script:
[codesyntax lang=”bash”]
#!/bin/bash [email protected] tracker=/usr/local/bin/whereibeen.txt CURDATE=`date` CURIP=$(curl -s http://www.edwiget.name/ip.php) if [ -f $tracker ]; then echo $CURDATE >> $tracker echo $(ifconfig eth0 | awk -F: '/inet addr:/ {print $2}' | awk '{ print $1 }') >> $tracker echo $(ifconfig wlan0 | awk -F: '/inet addr:/ {print $2}' | awk '{ print $1 }') >> $tracker echo $CURIP >> $tracker tar czfvp /usr/local/bin/whereibeen.txt.tar.gz /usr/local/bin/whereibeen.txt > /dev/null 2>&1 mutt -s "tracker attached" -a /usr/local/bin/whereibeen.txt.tar.gz -- ${EMAILS} < /dev/null else touch $tracker echo $CURDATE >> $tracker echo $(ifconfig eth0 | awk -F: '/inet addr:/ {print $2}' | awk '{ print $1 }') >> $tracker echo $(ifconfig wlan0 | awk -F: '/inet addr:/ {print $2}' | awk '{ print $1 }') >> $tracker echo $CURIP >> $tracker tar czfvp /usr/local/bin/whereibeen.txt.tar.gz /usr/local/bin/whereibeen.txt > /dev/null 2>&1 mutt -s "tracker attached" -a /usr/local/bin/whereibeen.txt.tar.gz -- ${EMAILS} < /dev/null fi # send the mail sendmail -oi ${EMAILS} << EOF From: [email protected] To: [email protected] Subject: COMPUTERNAME Booted: Booted on $CURDATE $CURIP Your COMPUTERNAME has just been booted on $CURDATE with IP $CURIP EOF
[/codesyntax]
So basically what I always did was placed an entry in /etc/rc.local like:
[codesyntax lang=”bash”]
/usr/local/bin/mailme.sh > /dev/null 2>&1
[/codesyntax]
But sometimes, especially with wireless, you may not always have a connection established when the system boots up. But the tracker file will at least have previous ip addresses. So what I did was made a secondary entry in crontab which then sends the email every 6 hours. You can always create a rule to file 13 the emails, until you really need them:
[codesyntax lang=”bash”]
* */6 * * * /usr/local/bin/mailme.sh > /dev/null 2>&1
[/codesyntax]
Leave a Reply
You must be logged in to post a comment.