I recently had an email request for a script I use to connect to the net in the wee hours of the morning and download any debian updates and do some basic house keeping tasks. Just in case anyone else is interested, I have included the script, and the cron syntax I use, in this message. What the script does is check for a dialup connection, dials one if none exists, cleans out apt's cache, updates the package list, downloads (but doesn't install) any updates, checks the disk usage, checks for any f-prot definition updates (I use f-prot to check a Samba share), and then synchronizes my system time with a time clock on the net. If it had to create a dialup connection, it disconnects afterwords. The cron job is then setup to email me the output. (I have it set up so it runs daily, at 5:30 AM). The whole script is written in bash (probably sh compatible though), and uses basic unix commands (cut, sed, grep, etc) for the most part. It does rely on having a working "pon" and "poff" command for dialing out. Of course, all this code is provided as-is, and I take no responsibility for it in the odd event that your machine has caught fire. If you find any bugs, or have any suggestions (and you probably do), please feel free to email the list or to email me personally. - Jesse Meyer PS: You will probably need to change the user this emails to, and the machine's name. Unless you run F-Prot A/V, you probably will want to remove that as well. Also, if you don't have ntp date installed, its probably worth commenting out that section. ======================== cron job ================================== # At 5:30 AM, run the system-tattler script 30 5 * * * /etc/scripts/system-tattler.sh \ | mail -s "System Tattler" dasunt &>/dev/null =============== /etc/scripts/system-tattler.sh ===================== #!/bin/sh # Author : Jesse Meyer # Last Update : Mar 18, 2003 # Version of this script VERSION=1.0 # Machine name SYSTEM=dagda # binary location and other info APT=/usr/bin/apt-get CUT=/usr/bin/cut DATE=`/bin/date` DF=/bin/df DEF_FILES=/usr/local/f-prot/*.DEF DEF_CUT=44-56,75- GREP=/bin/grep LS=/bin/ls POFF=/usr/bin/poff PON=/usr/bin/pon ROUTE_FILE=/proc/net/route SED=/bin/sed # has to be set after $GREP and $ROUTE_FILE is defined ISUP="$GREP -c ppp0 $ROUTE_FILE" # ignore variables after this STATUS=`$ISUP` DIDDIAL=0 echo "This report was generated by the system-tattler script, version $VERSION" echo "System : $SYSTEM" echo "Date : $DATE" # echo "========================================================================" if [ $STATUS -eq 0 ] then # echo "dialup link is down" # echo "attempting to dial" $PON # echo "waiting 120 seconds for connection..." sleep 120 STATUS=`$ISUP` if [ $STATUS -eq 0 ] then echo "========================================================================" echo "ERROR: cannot connect, aborting..." echo "========================================================================" exit fi # We had to dial this link, so... DIDDIAL=1 # else # echo "dialup link is up" fi # echo "========================================================================" echo "============================== disk usage ==============================" $DF -h echo "========================================================================" echo "============================ apt-get stats =============================" # echo "cleaning apt cache..." # echo "updating apt cache..." $APT clean > /dev/null if ( $APT -qq update &>/dev/null ) then # echo "apt-get update attempt succeeded - running dist-upgrade"; # Print the packages that are to be upgraded... $APT -u dist-upgrade | $SED -e '1,2d' # ...and download them $APT -d -qq dist-upgrade &>/dev/null else echo "apt-get update attempted failed - not running dist-upgrade"; fi echo "========================================================================" echo "======================= f-prot virus definitions =======================" # ls -lh *.DEF | cut -c 56-70,44-55 $LS -lh $DEF_FILES | $CUT -c $DEF_CUT echo "========================================================================" echo "============================= time update ==============================" /etc/init.d/ntpdate start echo "========================================================================" if [ $DIDDIAL -eq 1 ] then # echo "========================================================================" # echo "disconnecting link that was created..." $POFF # echo "========================================================================" fi ================================ End Script ================================ -- ...crying "Tekeli-li! Tekeli-li!"... ~ HPL icq : 34583382 | === ascii ribbon campaign === msn : dasunt@hotmail.com | () - against html mail yim : tsunad | /\ - against proprietary attachments
Attachment:
pgpFLmkU6tDgG.pgp
Description: PGP signature