Patrick van Bavel
Occasional Visitor
Hi,
I want to get a script running on my R7000 (using Advanced Tomato or DD-WRT).
The problem is the first line mentions to put it in JFFS and then run on startup, but I don't know how to do that..
Any help or manuals on this?
Regards,
Patrick
Script:
#!/bin/sh
#Enable JFFS2 and place script in /jffs/ then run on startup in web interface.
#You can check the log from http://192.168.1.254/user/wol.html
INTERVAL=2
PINGTIME=1
OLD_TIME=""
PORT=32400
WOLPORT=9
TARGET=192.168.2.250
BROADCAST=192.168.2.255
MAC=E8:06:88:CA:AE:71
WOL=/usr/sbin/wol
LOGFILE="/tmp/www/wol.html"
# Never change LOGLINESTOSTORE to under 100. It will create pretty much a loop on the cleanup log procedure
LOGLINESTOSTORE=500
PURGECOUNT=0
echo "<meta http-equiv=\"refresh\" content=\"10\">" > $LOGFILE
echo "["`date`"] AUTO WOL Script started. <br>" >> $LOGFILE
echo "For server: $TARGET:$PORT and MAC: $MAC on port $WOLPORT <br>" >> $LOGFILE
tcpdump -q -n -i any -p -P out -K -l -O -U 'dst host '$TARGET' and dst port '$PORT'' 2>/dev/null | while read NEW ; do
# Get the line in seconds, to minimize the number of processed commands.
NEW_TIME=`echo $NEW | awk -F'.' '{print $1}'`
if [ "$NEW_TIME" != "$OLD_TIME" ]; then
# Get the source IP for logging
SRC=`echo $NEW | awk -F'[.| ]' '{print $4"."$5"."$6"."$7}'`
# If box is alive (responding to ping)
if ping -qw $PINGTIME $TARGET >/dev/null; then
echo "[`date`] NOWAKE - $TARGET accessed by $SRC <br>">> $LOGFILE
#touch /dev/null
else
echo "[`date`] _WAKE_ - $TARGET accessed by $SRC <br>">> $LOGFILE
$WOL -i $BROADCAST -p $WOLPORT $MAC >> $LOGFILE
fi
OLD_TIME=$NEW_TIME
# Cleanup log file procedure, keeping the header and the last 10 last WAKE log lines
if [ "`wc -l $LOGFILE | awk -F'[ ]' '{print $1}'`" -gt "$LOGLINESTOSTORE" ]; then
head -n 3 $LOGFILE > /tmp/www/wol.tmp
PURGECOUNT=$((PURGECOUNT+1))
echo "Log File purged $PURGECOUNT times, last one at $NEW_TIME <br> " >> /tmp/www/wol.tmp
grep _WAKE_ $LOGFILE | tail -n 10 >> /tmp/www/wol.tmp
mv /tmp/www/wol.tmp $LOGFILE
echo "<br>" >> $LOGFILE
fi
sleep $INTERVAL
fi
done
I want to get a script running on my R7000 (using Advanced Tomato or DD-WRT).
The problem is the first line mentions to put it in JFFS and then run on startup, but I don't know how to do that..
Any help or manuals on this?
Regards,
Patrick
Script:
#!/bin/sh
#Enable JFFS2 and place script in /jffs/ then run on startup in web interface.
#You can check the log from http://192.168.1.254/user/wol.html
INTERVAL=2
PINGTIME=1
OLD_TIME=""
PORT=32400
WOLPORT=9
TARGET=192.168.2.250
BROADCAST=192.168.2.255
MAC=E8:06:88:CA:AE:71
WOL=/usr/sbin/wol
LOGFILE="/tmp/www/wol.html"
# Never change LOGLINESTOSTORE to under 100. It will create pretty much a loop on the cleanup log procedure
LOGLINESTOSTORE=500
PURGECOUNT=0
echo "<meta http-equiv=\"refresh\" content=\"10\">" > $LOGFILE
echo "["`date`"] AUTO WOL Script started. <br>" >> $LOGFILE
echo "For server: $TARGET:$PORT and MAC: $MAC on port $WOLPORT <br>" >> $LOGFILE
tcpdump -q -n -i any -p -P out -K -l -O -U 'dst host '$TARGET' and dst port '$PORT'' 2>/dev/null | while read NEW ; do
# Get the line in seconds, to minimize the number of processed commands.
NEW_TIME=`echo $NEW | awk -F'.' '{print $1}'`
if [ "$NEW_TIME" != "$OLD_TIME" ]; then
# Get the source IP for logging
SRC=`echo $NEW | awk -F'[.| ]' '{print $4"."$5"."$6"."$7}'`
# If box is alive (responding to ping)
if ping -qw $PINGTIME $TARGET >/dev/null; then
echo "[`date`] NOWAKE - $TARGET accessed by $SRC <br>">> $LOGFILE
#touch /dev/null
else
echo "[`date`] _WAKE_ - $TARGET accessed by $SRC <br>">> $LOGFILE
$WOL -i $BROADCAST -p $WOLPORT $MAC >> $LOGFILE
fi
OLD_TIME=$NEW_TIME
# Cleanup log file procedure, keeping the header and the last 10 last WAKE log lines
if [ "`wc -l $LOGFILE | awk -F'[ ]' '{print $1}'`" -gt "$LOGLINESTOSTORE" ]; then
head -n 3 $LOGFILE > /tmp/www/wol.tmp
PURGECOUNT=$((PURGECOUNT+1))
echo "Log File purged $PURGECOUNT times, last one at $NEW_TIME <br> " >> /tmp/www/wol.tmp
grep _WAKE_ $LOGFILE | tail -n 10 >> /tmp/www/wol.tmp
mv /tmp/www/wol.tmp $LOGFILE
echo "<br>" >> $LOGFILE
fi
sleep $INTERVAL
fi
done