Bradmont
04-06-2001, 12:28 AM
Well, I just wrote myself a little combination of a bash script and a couple little c++ apps to store my IP address in a file, then when the script is run, it checks my current IP against the logged one to see if it's changed, email the result to a web-based email account (for those annoying times when I'm away from the house & my IP changes, so I'll still be able to connect to my machine). I prolly could've done it entirely in bash, but then again I don't know bash...
But anyway, here's the problem (and no, this does not belong in the programming/scripting forum... at least I don't think it does ;))
I want to run the script in a cron job to execute once an hour. Now the script runs perfectly when activated from the command line, but doesn't seem to be executed by cron... I inserted the following line into my cron file:
16 * * * * /root/ipmail/ipmail
to get it to run at 16 minutes past every hour...
Here's the code for the script, if that helps:
#!/bin/bash
ifconfig > temp
/root/ipmail/getip temp moo
#takes the redirected output from ifconfig and extracts
#the IP addresses, storing them in the file 'moo'
/root/ipmail/compare moo /root/ipaddress
#This compares the file with the stored one, which is /root/ipaddress.
#It returns 2 if the files are different.
if [ $? = 2 ]
then
mail lordbradmont@gotmail.com < temp
rm /root/ipaddress
cp moo /root/ipaddress
fi
rm temp
rm moo
Thanx.
<edit> Heh, forgot to mention that it doesn't work from cron... </edit>
[ 06 April 2001: Message edited by: Bradmont ]
But anyway, here's the problem (and no, this does not belong in the programming/scripting forum... at least I don't think it does ;))
I want to run the script in a cron job to execute once an hour. Now the script runs perfectly when activated from the command line, but doesn't seem to be executed by cron... I inserted the following line into my cron file:
16 * * * * /root/ipmail/ipmail
to get it to run at 16 minutes past every hour...
Here's the code for the script, if that helps:
#!/bin/bash
ifconfig > temp
/root/ipmail/getip temp moo
#takes the redirected output from ifconfig and extracts
#the IP addresses, storing them in the file 'moo'
/root/ipmail/compare moo /root/ipaddress
#This compares the file with the stored one, which is /root/ipaddress.
#It returns 2 if the files are different.
if [ $? = 2 ]
then
mail lordbradmont@gotmail.com < temp
rm /root/ipaddress
cp moo /root/ipaddress
fi
rm temp
rm moo
Thanx.
<edit> Heh, forgot to mention that it doesn't work from cron... </edit>
[ 06 April 2001: Message edited by: Bradmont ]