1
Security and Networking / Wake On Lan (wol) Magic Packet
« on: February 19, 2010, 05:00:15 pm »
Anyone know how to send a WOL Magic Packet from a Zaurus?
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
#! /bin/bash
echo `date` checkmail run>>/home/root/checkmail.log
#It does keep a small log for debugging I find this useful to tell if it is waking up regularly to check mail
if [ "$1" != LIVE ]; then sleep 15; fi
#I find that if it starts too soon after wakeup it often fails Thus the sleep
#If I want it to not sleep I can put LIVE on the command line to make it hurry up
if ! grep -q mail\.domain\.net /etc/hosts; then echo 127.0.0.1 mail.lofland.net>>/etc/hosts;fi
#I find that DNS resolution often fails the first time over my cell phone connection
#Plus that eats up time and bits if you are charged either way
#So I just make sure the IP is in the hosts file and that elliminates DNS resolution
if ! grep -q mail\.domain\.net /home/root/.fetchmailrc; then echo poll mail.domain.net protocol IMAP user YOURUSERID with password YOURPASSWORD is root here>>/home/root/.fetchmailrc;fi
#These are the settings fetchmail needs I just have them set up automatically
#so that we do not have to worry about making sure we copy the file over
#NOTE if you do not use IMAP or need some other changes to how fetchmail works
#here is where to put them
#Google for fetchmail to find all of the options It is very powerful
chmod 710 /home/root/.fetchmailrc
#fetchmail complains if the perms are not just so on this file so I just set
#them each time to ellinate any possibility of fetchmail failing for this reason
touch /home/root/chdialing
#I had trouble with running over myself by trying to dial out when the script
#had already dialed out or it trying to dial out when I was already online
#This little system tries to overcome that
#it requires I use the script dial to connect and hangup to disconnect
#the GUI in pdaXrom does not work for me so I use these scripts
if [ ! -f /home/root/mandialing ] && [ ! -f /home/root/stonline ]
then
echo ch dialing>>/home/root/checkmail.log
/usr/sbin/pppd -d
fi
#pppd actually dials the connection
#notice that if there is no bluetooth card is in the CF slot then pppd has no affect
#and the script continues on and tries with whatever connection it may or
#may not have
#which is just what I want
cd /home/root
if [ ! -f savenum ]
then
echo "0">savenum
fi
#savenum is where we save the results of the last mail check
oldnum=`cat savenum`
nums=`/usr/sbin/fetchmail -f /home/root/.fetchmailrc -k -c 2>/dev/null | tr -d '(' | cut -f1,3 -d' '`
#there is the meat of the script where fetchmail does the actual work
#again GOOGLE for the fetchmail man page and see the options
#it is very powerful and can work with almost any mail account POP or IMAP
echo `date` $nums>>/home/root/checkmail.log
currentnum=`echo $nums | cut -f1 -d' '`
readnum=`echo $nums | cut -f2 -d' '`
if [ "X$currentnum" != X ]; then
echo $currentnum>savenum
if [ $currentnum -gt $oldnum ]
then
echo "New mail!"
/usr/X11R6/bin/xmessage -display :0.0 -default okay -c New Mail &
/usr/bin/esdplay /home/root/sounds/tinkalink2.wav
#mplayer /opt/kdepimpi/kdepim/korganizer/koalarm.wav >/dev/null 2>&1
elif [ $currentnum -gt $readnum ]
then
/usr/bin/esdplay /home/root/sounds/reminder.wav
/usr/X11R6/bin/xmessage -display :0.0 -timeout 30 -default okay -c UNREAD Mail &
echo "UNREAD Mail"
else
echo "No new mail . . ."
fi
else
echo "Fetchmail ERROR"
fi
if [ ! -f /home/root/mandialing ] && [ ! -f /home/root/stonline ]
then
echo ch hanging up>>/home/root/checkmail.log
/etc/ppp/ppp-off
fi
rm -f /home/root/chdialing
echo -n 30
Of course, just change the number to make it wake up more or less often#! /bin/bash
echo `date` 300checkmail run>>/home/root/checkmail.log
if [ ! -f /home/root/savenum ]
then
/home/root/checkmail &
elif [ "`find /home/root -maxdepth 1 -name savenum -mmin +15`" = "/home/root/savenum" ]
then
/home/root/checkmail &
fi
Notice that it is going to use the timestamp on savenum to avoid checking more often than every 15 minutes. That way if you wake it up 3 times in 20 minutes, you don't get a mail check 3 times.ln -s /bin/vi /usr/bin/vi
Now, to set up the cron job just type:crontab -e
And put in this line (change the number for different interval):*/30 * * * * /etc/apm/resume.d/300checkmail
touch /home/root/mandialing
if [ ! -f /home/root/chdialing ] && [ ! -f /home/root/stonline ]; then pppd -d;fi
touch /home/root/stonline
rm -f /home/root/mandialing
if [ ! -f /home/root/chdialing ] && [ ! -f /home/root/mandialing ]; then /etc/ppp/ppp-off;fi
rm -f /home/root/stonline
rm -f /home/root/mandialing
/home/root/dial
sylpheed
/home/root/checkmail LIVE
/home/root/hangup