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 a daily bandwith log & it works...so I'm attempting to write my first script to get more info out of the router. I'd like to get an email whenever ANY (wired/wireless) active client comes on/off the network. This is what I have figured out so far:
Quote:
#!/bin/sh
arp>/opt/arpnew.lst
if ["$(cat /opt/arpnew.lst)" = "$(cat /opt/arpold.lst)"] ;
then [];
elseif
sendmail -S"mail.optonline.net" -f"xxx@xxx.net" -F"DD-WRT" -d"optonline.net" -s"DD-WRT Hosts change" -m"$(cat /opt/arpnew.lst)" xxx@gmail.com ;
cp /opt/arpnew.lst /opt/arpold.lst
fi
Ideally I'd like to put this in as a custom script with a CRON job to run every minute or two minues, but I cant seem to get it working!
Currently it does output to the arpnew.lst file, but does not seem to do the comparing OR copying to arpold.lst
Any assistance or pointers would be greatly appreciated!
Joined: 19 Jun 2010 Posts: 118 Location: Brooklyn, NY
Posted: Wed Apr 18, 2012 1:07 Post subject:
This may be a stupid question, but is sendmail installed and running on your router? _________________ Linksys E900 dd-wrt v24-sp2 18946 mini
Linksys E3000 dd-wrt v24-sp2 15692 std-usb-nas
D-Link DIR-601 Gargoyle 1.5.3 ar71xx dir 600 a1 squashfs
I'm going to say yes?
This is the original copy of the working bandwith script:
Quote:
#!/bin/sh
#
# 03-20-2012 --- RNR
# Brokeout all the personal variables to make it easier to modify.
# Added $comcast variable to make it work with . . .
#
# 03-07-2012 --- RNR
# Added DNS lease information to the end of the report.
#
# 01-24-2012 --- RNR
# Modified for DD-WRT Rev > 17628.
#
# 08-18-2011 --- RNR
# Bandwith report by email, custom script for DD-WRT .
# From: Useful Scripts Wiki --- Email Bandwidth Usage Daily
#
who=$(echo "\"$(nvram get wl0.1_ssid)\" is connected to \"$(nvram get wl0_ssid) - - $(wl -i eth1 assoclist | awk '{print $2}')\" at this time.")
msg=$(echo "\n$who\n\n$upm\n $upt\n\n$tmp\n $tmp0\n\n$tmp1\n $tmp2\n\n$tmp3\n")
fnc_mail "Router Bandwidth Report for $ydat" "$msg" "/tmp/bwmail.log"
Posted: Wed Apr 18, 2012 1:56 Post subject: ARP/active client list email
Got it working! This script will output ARP to a file & check it against a "cached" version. If it is different, it will be emailed to you...if not different, it just resets itself for the next check. I wanted this so that I could see ALL active clients, not just wireless.
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
I know its gross & probably can be refined...but its my first script!
I have it stored in /opt & it runs every 10 mins with a CRON job
Any thoughts, LMK
Well...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