[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

RE: Cron quirk

> Hello all, I have a little frustrating problem with cron.  I have a script
> that mails me some reports.  I set a cronjob to mail me the reports at a
> certain time.  However, the reports are never mailed.  If I run the script
> from the command line, it works fine.   Other cronjobs I have
> work fine too.
> It is just this one script, which uses sendmail, just does not
> want to send
> me anything as a cronjob...
> Any thoughts?
> Gracias,
> Aeryn

Check your path/environment variables in your cron script.  None of these
are set when run out of cron (versus running from a shell).  You are
probably running a command that it cannot find in its path.  One thing I do
when I can with most of my scrpits is reference full path name for commands
...  (even the non-cron ones I do this.. just good practice for security

e..g if you are running the sendmail command in your script, instead of

echo "" | sendmail -v root
i'd use

/bin/echo "" | /usr/lib/sendmail -v root

If you have more problems, use
#!/bin/bash -x
at the top of the script (this does a verbose output..very verbose), call
the cron script from another script (in cron) and redirect output to a text
file so you can see what it's doing ...

so if your cron scrpit is cronscript1.sh , put the

#!/bin/bash -x

on the top of cronscript1.sh .. then create asecond script (say
cronscript2.sh) that does this


/full/path/to/cronscript1.sh >& /tmp/output.txt

and run cronscript2.sh out of cron

Ben Yau

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]