Can't get a cron job to run
So I'm a newb to cron, I've never used it before. After reading a bit online, I did the following:
ran "contrab -e" as the user I wanted to run my script as. I entered the line "*/10 * * * * zoklet.net /home/zoklet.net/zok_OTG/run", saved and quit (:wq) When I view the log file /etc/log/crontab and it showed the script running correctly: Code:
Dec 15 16:20:01 zoklet crond[15319]: (zoklet.net) CMD (zoklet.net /home/zoklet.net/zok_OTG/run) Run Script: Code:
perl getmail.pl > out.txt Code:
# Script connects to said gmail account, checks for new messages Code:
[zoklet.net@zoklet zok_OTG]$ ls -al |
The most likely cause of this problem is that perl may not be on cron's PATH. Try giving the full path names for the perl command and getmail.pl in your script.
------------------ Steve Stites |
I just edited the file now. We'll see what happens in 6 minutes.
|
Dec 15 17:50:01 zoklet crond[16235]: (zoklet.net) CMD (zoklet.net /home/zoklet.net/zok_OTG/run)
out.txt is still empty and the mail has yet to be downloaded, no luck :/ |
You can try to redirect standard error to standard output, otherwise if your script generates some errors you don't catch them. So you can simply add redirection to the perl commandline
Code:
perl getmail.pl > out.txt 2>&1 |
I think I know what it is. Cron is picky and usually doesn't like file extensions. Remove the ".pl" from the filename (leaving just "getmail"). Then you need to put this line (shebang) as the very first line of the file (before the comments):
Code:
#!/usr/bin/env perl -w Code:
chmod +x getmail |
I added the shebang to my perl file, removed the .pl from the end of the file name, and added 2>&1 to my run file. None of those seemed to work :/
out.txt is still empty, the script hasn't been run, there are no errors in the cron log file, and there is no mail for the users zoklet.net or root. |
Unless you have not previously touched (that is created an empty) out.log, the script has run. Anyway, you can
1. verify that the cron daemon works properly (and that particular user is allowed to run cron jobs) by testing with a simple crontab, like Code:
* * * * * /bin/echo $HOME >> $HOME/test.log Code:
MAILTO=zoklet.net |
The first test did work, I'm trying the second now. What does the MAILTO= line do? Will that send any error messages to my system mail? Also, will the perl script output to the console if it's run by cron? Either way, I'll sit and wait another 5 minutes to see what happens.
Edit: No output: Code:
[zoklet.net@zoklet zok_OTG]$ date |
Problem solved! It turned out to be the absolute path that was causing problems. That makes a lot of sense, now that I think about it. Thanks for all of your help, guys!
|
I assumed that it was not an issue, since jailbait correctly suggested the solution in post #2 and you told to have followed his advice in post #3...! Anyway, regarding the MAILTO question, here is an excerpt from "man 5 crontab":
Quote:
|
All times are GMT -5. The time now is 03:27 AM. |