Results 1 to 10 of 13
hi, i have a simple script that runs two other pythong scripts and then sends an emails, something like:
echo starting
python script.py > temp
mail -s "Hello" "user@host.com" < ...
- 09-26-2007 #1Just Joined!
- Join Date
- Sep 2007
- Posts
- 12
when run by cron bash script doesn't send an email
hi, i have a simple script that runs two other pythong scripts and then sends an emails, something like:
echo starting
python script.py > temp
mail -s "Hello" "user@host.com" < temp
echo finishing
very straight forward, and works perfectly when run by
sh script.sh
i.e i get an email with the ouptut script.py gave.
but, when i schedule a cron job that looks like:
* * * * * sh script.sh >> cronLog
i see that the script is runned every minute (the cronLog exists & is updated with the correct data every minute), but i get no email... any idea why?
P.S
i made the script run every minute just so i can understand what goes wrong. after it'll work i'll change it to once a day.
- 09-27-2007 #2Just Joined!
- Join Date
- Sep 2007
- Location
- Lafayette, IN
- Posts
- 83
My first thought is that perhaps it is a path issue. Try putting full paths to executables and files, or setting your $PATH environment variable. I think the first step in debugging is to dump the output of your python script to a file you can keep and look at, to make sure that it runs as expected from cron. If not, then you can figure out why. If it does, then you move on to debugging the mail line.
- 09-27-2007 #3Just Joined!
- Join Date
- Sep 2007
- Posts
- 12
It doesn't have anything to do with the python script - I tried leaving out the python line in the file:
echo starting
mail -s "Hello" "user@host.com" < temp
echo finishing
(when of course "temp" exists)
i would have known if one the script failed at any point since the cron outputs to a log file, but when i look at the log i don't see any errors...
- 09-27-2007 #4Just Joined!
- Join Date
- Sep 2007
- Location
- Lafayette, IN
- Posts
- 83
Okay, so let's try it a different way. First, check to see that mail is not the problem
You should get an e-mail containing the output of the date command. If so, then the problem may be that you need to specify the path to the file 'temp' (e.g. ~/temp or /tmp/temp). If not, then we'll try something else.
Originally Posted by code
- 09-27-2007 #5The majority of cronjob problems are related to the limited PATH used by cron.
Originally Posted by Ben Cotton
Try using the FQ name for mail in your cronjob.
- 09-29-2007 #6Just Joined!
- Join Date
- Sep 2007
- Posts
- 12
- 09-29-2007 #7
Yes - close enough. I intended for it to mean Fully Qualified. You can probably determine this from a terminal using which mail.
e.g. On my CentOS box:
P.S. What's curious is that, IIRC, /bin should already be part of cron's PATH. In any case, it won't hurt to try.Code:[fugu ~]$ which mail /bin/mail
If this does not solve the problem, then I'd recommend changing the user@host.com to a local account on your Linux box. After doing so, check if mail is getting to the local account. That way you can quickly determine whether mail is acting up (as opposed to an external problem).Last edited by anomie; 09-29-2007 at 01:02 AM. Reason: added stuff.
- 09-29-2007 #8Just Joined!
- Join Date
- Sep 2007
- Posts
- 12
Ok, until now i thought that if the script would encounter any errors they would be appended to the log file just as the echoed messages, but i added a jibberish line to the executed script, and when it's run on it's own it does output an error message, but when run from cron i see no error messages in the log. is there a flag or something else i can use to tell cron to run the script and also get the errors the script encounters?
- 09-29-2007 #9
Did you try either of those suggestions? It's fairly frustrating to have advice completely ignored, only to read new questions that may be heading down a blackhole tangent...
Looking back at your thread: Add the python instruction back in, using python's FQ path, and I'd expect it to work.
- 09-29-2007 #10Just Joined!
- Join Date
- Sep 2007
- Posts
- 12
Sorry, i can understand your frustration. I didn't ignore your message. i started investigating it, but once i started trying to set the PATH i noticed i never see any error messages in the log. then i realized that first thing i should do is get the error messages so i'll know what's not going right. anyway, it's indeed a PATH problem - i changed all file paths referenced in the script to FQ and now the script works perfectly. IMO, I think it's better than adding more paths to the PATH var since there should quite alot of those as the files the script uses are located at different directories (correct me if i'm wrong).
Thanks, noam


Reply With Quote
