Problem with cron

deraven

Registered
I've written a shell script that is SUPER simple and it works fine when I envoke it, but not when it's run by cron.

All the script does is send mail to an address (passes sendmail a file to send the contents of).

When the specified time from crontab rolls around, and I do:

ps -aux | grep send

the sendmail task shows up, and the system log shows it running and returning normal output, but the message never sends.

If I copy-&-paste it from the crontab and just run it from terminal it sends just fine.

Here's the crontab entry:

15 22 * * * root sh /bin/remindermail 2>&1 | tee /var/log/daily.out | mail -s "`hostname' Reminder Text Message Sent to xxxxxxxxx" root


And here's the contents of the remindermail script:

#!/bin/tcsh
sendmail xxx@xxxxxx.xxx < /users/xxxxxxx/ReminderMailMessage.txt



(yes, usernames and such were just replaced with "xxxx" for this posting)

Any ideas?
 
Originally posted by deraven
I've written a shell script that is SUPER simple and it works fine when I envoke it, but not when it's run by cron.
...
Here's the crontab entry:

15 22 * * * root sh /bin/remindermail 2>&1 | tee /var/log/daily.out | mail -s "`hostname' Reminder Text Message Sent to xxxxxxxxx" root
...
Any ideas?
If this is being added to a user crontab (via crontab -e) you don't want the user specification in there,
Code:
15 22 * * * /usr/local/bin/myscript
Only if you are adding something to /etc/crontab do you use the user specification.
 
This is, indeed, in /etc/crontab, not a user's.

Also, on further investigation, it appears that some of the sendmail jobs started by cron may have been directed to /dev/null instead of the address that was specified.

Again, the script works fine if I execute it manually, but when called from the crontab it may be sending the message to /dev/null.
 
Huh... well, I got it to work...

Here's the only thing I found that looked the least bit odd in the crontab:

`hostname'

Notice the difference between " ' " and " ` " - I didn't either.

I changed:

`hostname'

to

`hostname`

and all is well.

So, uh, yeah. Odd.
 
Back
Top