image
image

Go Back   macosx.com > Mac Help Forums > Unix & X11

Reply
 
Thread Tools
  #1  
Old January 28th, 2003, 09:49 PM
profx's Avatar
ill never 4get watsisname
 
Join Date: May 2001
Location: Auckland New Zealand
Posts: 386
Thanks: 0
Thanked 0 Times in 0 Posts
profx is on a distinguished road
cron tab help

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?
__________________
| PowerBook G4 550 - 10.4 - 512Mb - 20Gb | 30Gb iPod Photo | 40x12x48 Fantom Drives CDRW (firewire) | Logitech Cordless Mouse MX700 | xBox with XBMC for movies and music in the lounge
Reply With Quote
  #2  
Old January 28th, 2003, 10:02 PM
michaelsanford's Avatar
Psycholinguist
 
Join Date: Oct 2002
Location: Ottawa/Montrιal
Posts: 2,174
Thanks: 0
Thanked 0 Times in 0 Posts
michaelsanford is on a distinguished road
This is a better way IMHO.

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?
__________________
michaelsanford.com • Blog • Twitter • Tumblr • LinkedIn
• iMac Aluminum 24" |
MacOS X 10.5-current | 3.06 GHz Intel Core Duo | 4 GB RAM | 1 TB HDD
• iBook G4 1.42 GHz | MacOS X 10.5-current | 1 GB RAM, 100 GB HDD
• AMD Athlon64 3500+ | Slackware 12 (2.6.21.5-smp) | 2 GB RAM, 2•120 GB RAID 1, 2•500 GB RAID 0
Reply With Quote
  #3  
Old January 29th, 2003, 01:34 AM
profx's Avatar
ill never 4get watsisname
 
Join Date: May 2001
Location: Auckland New Zealand
Posts: 386
Thanks: 0
Thanked 0 Times in 0 Posts
profx is on a distinguished road
Lightbulb

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.
Attached Files
File Type: txt ipupload.txt (1.7 KB, 3 views)
__________________
| PowerBook G4 550 - 10.4 - 512Mb - 20Gb | 30Gb iPod Photo | 40x12x48 Fantom Drives CDRW (firewire) | Logitech Cordless Mouse MX700 | xBox with XBMC for movies and music in the lounge
Reply With Quote
  #4  
Old January 29th, 2003, 11:21 AM
Writer, et. al.
 
Join Date: Aug 2002
Location: Boulder, CO
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
d1taylor is on a distinguished road
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 youremail
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... :-)
__________________
Author, Learning Unix for Mac OS X (O'Reilly), among other books.
Check out http://books.intuitive.com/
Reply With Quote
  #5  
Old January 29th, 2003, 07:53 PM
profx's Avatar
ill never 4get watsisname
 
Join Date: May 2001
Location: Auckland New Zealand
Posts: 386
Thanks: 0
Thanked 0 Times in 0 Posts
profx is on a distinguished road
i gave the full path to ifconfig in the script and now it works correctly. Thanks anyway!!
__________________
| PowerBook G4 550 - 10.4 - 512Mb - 20Gb | 30Gb iPod Photo | 40x12x48 Fantom Drives CDRW (firewire) | Logitech Cordless Mouse MX700 | xBox with XBMC for movies and music in the lounge
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron Help Please emh_alpha1 Unix & X11 7 October 26th, 2002 01:14 PM
Terminal: Where have thy tab completion gone? reverendsin Unix & X11 3 August 27th, 2002 09:53 AM
cron process not starting up sinebubble Mac OS X System & Mac Software 2 March 11th, 2002 01:10 AM
How do you get cron to work? buc99 Mac OS X System & Mac Software 1 January 2nd, 2002 04:32 PM
mysqldump and cron aussieron Mac OS X System & Mac Software 2 November 6th, 2001 05:45 PM


All times are GMT -5. The time now is 07:23 AM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.