I am running a DD-WRT enabled Linksys WRT350N router
To say I'm a novice bash/C/UNIX programmer is an overstatement, but I learn as I go
I've cobbled together a script that emails me when clients sign on/off my network:
Quote:
#!/bin/sh
fnc_mail() {
subj="$1"
msg="$2"
my_mail_addr="ADMIN EMAIL ADDRESS"
my_mail_to="YOUR EMAIL ADDRESS"
my_smtp="mail.optonline.net"
my_username="xxx"
my_passwd="xxx"
comcast="-d optonline.net"
if [ -z "$3" -o "$(dirname $3)" = "." ]; then logfile="/opt/lastsentmail.log"; else logfile="$3"; fi
echo "From: $(nvram get router_name)<$my_mail_addr>" > /opt/arpmsg.txt
echo "Subject: $subj" >> /opt/arpmsg.txt
echo "To: $my_mail_to" >> /opt/arpmsg.txt
#echo -e $msg >> /opt/arpmsg.txt
cat /opt/arpnew.txt >> /opt/arpmsg.txt
x=0
while [ $x -le 3 ]

o
## rnr ##
cat /opt/arpmsg.txt | sendmail -S $my_smtp -f $my_mail_addr $comcast > $logfile 2>&1
if [ "$(cat $logfile | grep 221 | awk '{print $1}')" = "221" ]; then break;fi
echo -e "\nSend Count = $x" >> /opt/arpmsg.txt
cat $logfile | grep -v 250 | grep -v 334 | grep -v 235 | grep -v 354 | \
grep -v 220 | grep -v 221 >> /opt/arpmsg.txt
sleep 120s
x=`expr $x + 1 `
done
}
arp > /opt/arpnew.txt
cmp -s /opt/arpnew.txt /opt/arpold.txt > /dev/null
if [ $? -eq 1 ];
then
msg=$(cat /opt/arpnew.txt)
fnc_mail "Router Active Clients" "$msg" "/opt/arpmail.log"
cp /opt/arpnew.txt /opt/arpold.txt
rm /opt/arpnew.txt
else
rm /opt/arpnew.txt
fi
In typical fashion for discovering new horizons, I've met a new issue
When I run the script through the command line:
Quote:
sh -x /tmp/custom.sh
It works just fine, but when the cron job runs I get emails w/ blank body
I know cron requires "absolute" paths (???) and I though I specified that everywhere, but I cant figure out whats going on now
cron command i'm using is:
Quote:
*/5 * * * * root /opt/arpmail.sh
Any assistance would be greatly appreciated!