cron vs command-line

cron vs command-line

Post by Franci » Tue, 25 Sep 2001 14:35:10



Hi expert,
    I have a short script which perform a "ping" test every minute. It
work perfectly in command line mode and report the appropriate "ping"
results.

    However, when I put it in as a "cron" job, it never reports the
correct "ping" status. It always reports the host is DEAD, even if it's
ALIVE ......

    Please help. Thanks.

    Here's the script:

#!/bin/sh

# this script can run in command line, but won't work in crontab

filename=/tmp/abc_ping_status

Quote:>> $filename

ping abc 3
if [ $? -eq 0 ]; then
   printf "abc ALIVE \n" >> $filename
else
   printf "abc DEAD \n" >> $filename
fi

Regards,
Francis.

 
 
 

cron vs command-line

Post by Michael Heimin » Tue, 25 Sep 2001 15:41:31



Quote:> Hi expert,
>     I have a short script which perform a "ping" test every minute.
>     It
> work perfectly in command line mode and report the appropriate
> "ping" results.

>     However, when I put it in as a "cron" job, it never reports the
> correct "ping" status. It always reports the host is DEAD, even if
> it's ALIVE ......

>     Please help. Thanks.

>     Here's the script:

> #!/bin/sh

> # this script can run in command line, but won't work in crontab

> filename=/tmp/abc_ping_status
>>> $filename
> ping abc 3
> if [ $? -eq 0 ]; then
>    printf "abc ALIVE \n" >> $filename
> else
>    printf "abc DEAD \n" >> $filename
> fi

> Regards,
> Francis.

You should try to put in the full path to your ping binary.

Michael Heiming

 
 
 

cron vs command-line

Post by Markus Boehme » Tue, 25 Sep 2001 21:18:11



> Hi expert,
>     I have a short script which perform a "ping" test every minute. It
> work perfectly in command line mode and report the appropriate "ping"
> results.

>     However, when I put it in as a "cron" job, it never reports the
> correct "ping" status. It always reports the host is DEAD, even if it's
> ALIVE ......

>     Please help. Thanks.

>     Here's the script:

> #!/bin/sh

> # this script can run in command line, but won't work in crontab

> filename=/tmp/abc_ping_status

>>>$filename

> ping abc 3
> if [ $? -eq 0 ]; then
>    printf "abc ALIVE \n" >> $filename
> else
>    printf "abc DEAD \n" >> $filename
> fi

> Regards,
> Francis.

Try to set the PATH variable in the Skript...perhaps ping could not be
found by cron.

--
Markus B?hmer
Datenbankentwickler
SSI Sch?fer Shop GmbH

 
 
 

cron vs command-line

Post by Danny Faugh » Thu, 27 Sep 2001 12:23:55



> Try to set the PATH variable in the Skript...perhaps ping could not be
> found by cron.

Yup, and sometimes it lives in strange places.  To debug cron problems,
try to redirect all output to a log file, or tell cron to mail you the
output.  Then you'll be able to see the error messages.

Also, it's worth pointing out that on most systems I've used, you can't
rely on ping's return code.  I have to resort to grepping the output.  I
have annotated code samples at
http://home.tejasconsulting.com/resources/toolbelt/simplemon.sh and
http://home.tejasconsulting.com/resources/toolbelt/simplemon_port.sh.
These are based on my "Scripts on My Tool Belt" presentation at
http://tejasconsulting.com/papers/toolbelt/toolbelt.ppt.  
--
Danny Faught
Tejas Software Consulting
http://www.tejasconsulting.com

 
 
 

cron vs command-line

Post by dwillmo » Tue, 25 Sep 2001 21:57:08


yeah,

the others are correct.

a cron job does not execute your $HOME/.profile
in fact, a cron job may be run under the system $SHELL
and it may not recognize your $SHELL commands.

nor does the cron job have your $PATH, so yes,
explicit paths are required


> Hi expert,
>     I have a short script which perform a "ping" test every minute. It
> work perfectly in command line mode and report the appropriate "ping"
> results.

>     However, when I put it in as a "cron" job, it never reports the
> correct "ping" status. It always reports the host is DEAD, even if it's
> ALIVE ......

>     Please help. Thanks.

>     Here's the script:

> #!/bin/sh

> # this script can run in command line, but won't work in crontab

> filename=/tmp/abc_ping_status
> >> $filename
> ping abc 3
> if [ $? -eq 0 ]; then
>    printf "abc ALIVE \n" >> $filename
> else
>    printf "abc DEAD \n" >> $filename
> fi

> Regards,
> Francis.

 
 
 

1. Sendmail from cron vs. command line

Hi,

/usr/lib/sendmail will certainly use its sendmail.cf file.
The error must be somewhere else.

Consider this version:

cd /export/home2/spiderman/queue
MDATE=...
LOGFILE=...
# turn shell expansion on in case it was off
set +f
for i in [0-9]*email
do
  # ensure this is a readable file:
  [ -f "$i" ] || continue
  # probably not needed:
  # chmod 777 "$i"
  echo " PROFILE MAILER START"
  echo " ============================================== "
  cat "$i"
  /usr/bin/perl "$i" 2>&1
  # sendmail is CPU-intensive - give the system a breath
  sleep 1
  rm -f "$i"
  echo " ============================================== "
  echo " PROFILE MAILER SENT"
done >> $LOGFILE
exit 0

If I understand right, the script should execute whatever
it finds with a /usr/bin/perl interpreter.
A bit strange, and a bit risky...

What do you mean by "return path"?

--

2. HELP with USB iomega 100 drive

3. command-line access to parsed vs. unparsed HTML on Apache

4. how to set gateway with 2 routers.

5. Desktop vs. Command Line, was Linux vs. OS/2

6. Apache 1.3.12 config

7. cron fails; command line OK

8. MU7 Install Problem

9. Command Line and Cron

10. How to tell if script is run from cron or command line?

11. Command Line Script runs fine get bad substititon from cron

12. Crond help: Script Runs from command line, but not from cron