Quantcast

Forums | MacLife

You are not logged in.

#1 2007-09-16 3:29 pm

lord funk
Title
Registered: 2000-12-11
Posts: 2276

'cron' script doesn't run correctly

I've got a shell script that runs great when called from the terminal, but when 'cron' calls it, it seems to skip a line.  Specifically, it doesn't look like it is calling 'ifconfig.'

The script is this (it's an IP reporter):

Code:

#! /bin/bash
cd /Users/KSE581/
date "+date: %a %b %d %H:%M:%S %Y" > ip_email.txt
echo "to: email@email.com" >> ip_email.txt
echo "subject: subject" >> ip_email.txt
echo "from: email@gmail.com" >> ip_email.txt
echo "" >> ip_email.txt
ifconfig >> ip_email.txt
/usr/sbin/sendmail -t < ip_email.txt

When called by cron (either as root or user), it correctly sends the email, but the ifconfig part of the body is not there.  Why won't it run ifconfig?


In and around the lake,
Mountains come out of the sky
And they stand there!

Offline

 

#2 2007-09-16 3:56 pm

lord funk
Title
Registered: 2000-12-11
Posts: 2276

Re: 'cron' script doesn't run correctly

More searching indicates that while 'ifconfig' works in the bash environment, it doesn't in the sh environment, which is the cron default.  I don't even know if I can change that...


In and around the lake,
Mountains come out of the sky
And they stand there!

Offline

 

#3 2007-09-16 7:08 pm

Fracai
Evacipate
From: St. Elsewhere
Registered: 2000-05-25
Posts: 2837

Re: 'cron' script doesn't run correctly

you have #!/bin/bash at the top which sets the environment that the script is running under
you might need to call ifconfig with it's full path: /sbin/ifconfig


   i am jack's amusing sig file
        http://alum.wpi.edu/~arno/i/s.png
Satellite Lot :: Second Summer

Offline

 

#4 2007-09-17 11:52 am

lord funk
Title
Registered: 2000-12-11
Posts: 2276

Re: 'cron' script doesn't run correctly

Fracai wrote:

you have #!/bin/bash at the top which sets the environment that the script is running under
you might need to call ifconfig with it's full path: /sbin/ifconfig

THANK YOU.  In one sentence you fixed what hours of Google hunting could not do.


In and around the lake,
Mountains come out of the sky
And they stand there!

Offline

 

Board footer

Powered by PunBB 1.2.6
© Copyright 2002–2005 Rickard Andersson