cron tab help

profx

ill never 4get watsisname
i am making a script that uploads my ip address to a website. It works perfectly when run from terminal. The shell i am using is sh



Code:
ifconfig | tail -1 | tr " " "\n" | head -2 | tail -1

this line gives me my ip address on interface ppp0

however when this is run from the cron tab at the specfied time it outputs nothing, rendering my script useless.

WHY???

by the way is there a better way of getting the ip address off interface ppp0?
 
I did exactly this about a month ago.

The shell script:
Code:
#!/bin/tcsh
cd /Users/gwailo/update_ip
nice +20 date > ip.txt;
nice +20 echo "<br>" >> ip.txt;
nice +20 echo "Current WAN IP Address: <br><b>" >> ip.txt;
nice +20 /sbin/ifconfig ppp0 | grep inet | awk '{print $2}' >> ip.txt;
#date >> log.txt
nice +20 ftp ftp.domain.com < connect.ftp >> ftp_log.txt

The connect.ftp script:
Code:
type ascii
cd Sites/ip
put ip.txt index.html
bye

Now just put the script into the SYSTEM crontab (I like the CronniX interface) to be run as YOUR USER.

Note that this also assumes that you have ~/.cshrc configured so that it can login via ftp automatically, without having to leave the username and password in cleartext in the script.

Maybe move this to HOW-TO & FAQs? ;)
 
Attached is my script. It creates a formatted html page with the date and your ip and uploads to a ftp server - just put in your ftp host, username and password

All you need to do is add a cron job to make it automaticaly run every hour or so!


Anyone know how to make a script run when the dialup ppp connection is made? I know OSX runs a few scripts because you can see 'sh' run a few times in top. That would be the perfect solution!!

You might want to rename the attachment to have a .sh extention for 'proper' form. I have made this an invisible file in my home directory by naming it .ipupload.sh.
 

Attachments

  • ipupload.txt
    1.7 KB · Views: 3
What's probably failing in your cron job is that those jobs run with a different PATH than your login shell. You can experimentally verify it with a crontab entry like:
Code:
30 * * * *   env | mail -s env [i]youremail[/i]

What I do is add something like
Code:
PATH=/sbin:/bin:/usr/sbin:/usr/bin
in the scripts as needed (theoretically you can add that to your master crontab file too, but I find that doesn't work reliably, for reasons that only Paul Vixie knows... :)
 
i gave the full path to ifconfig in the script and now it works correctly. Thanks anyway!!
 
Back
Top