Crontab not working ...
Hi there,
I created a very simple cron job for testing my first Linux system but It doesn't work. After open the crobtab file by typing crontab -e, I put a line like this to send email in every 2 minutes to report disk usage: MAILTO=dan@gmail.com */2 * * * * du -s /home I tried to restart cron several times but I still got nothing worked. /etc/init.d/crond restart Please help! Thank you so much! |
Quote:
Try sending it to a local user first, to eliminate the mail server problem. It is also a good security practice to use the full pathname of any command you use in a cron job, especially if it is run as root. Check your processes, and see if it is running the command every two minutes. (ps -ef |grep "du -s") Worst case, you can check your syslog or messages logs and see if there are any errors. |
Wow, wow ...
It's a super-quick response. I love this forum. Man, It's great. Kernl, I just changed it to a simpler cron job like this: */2 * * * * echo "testing" but it doesn't work ether. I think that there is something wrong with cron in my system. By the way, how can I open the message logs in order to see errors? Thank you! |
Hi Kernl,
I used your command (ps -ef | grep "du -s"), I got only one line: root 16475 3427 0 12:52 tty1 00:00:00 grep du -s If I used command ps -ef, I got many lines but the times are all 00:00:00. Is there something wrong in my system? Regards, Dan |
actually, the time you are referring to is the time the process is using for the command it represents.
Here are some steps for you to see what is going on. Check to see if anacron, or cron is running on your system: ps -ef |grep -i cron you should see something like this: root 5091 1 0 15:40 ? 00:00:00 /usr/sbin/cron root 10494 5091 0 16:30 ? 00:00:00 /USR/SBIN/CRON root 10509 5091 0 16:39 ? 00:00:00 /USR/SBIN/CRON root 10512 5091 0 16:40 ? 00:00:00 /USR/SBIN/CRON kernl 10585 10516 0 16:43 pts/0 00:00:00 grep -i cron If not, your cron is probably not running, and you need to start it. sudo /etc/init.d/cron start then check again to see if it is running. To check your syslog files type: less /var/log/syslog |grep -i cron that should let you know if you are capturing the cron error messages. you can also type this in a separate console: tailf /var/log/syslog or if you don't have tailf on your system: tail -f /var/log/syslog that will scroll the error messages as they occur. Hope that helps. |
Quote:
* * * * * echo "Testing">>/tmp/foo.$$ Then go to /tmp, and see if you start getting files with foo.somekindofnumber the $$ at the end will translate to the process number used to generate the command. Don't let it go too long though, or you might fill up /tmp and that would not be good. Cheers |
Quote:
First lets see if the cron daemon is running Code:
ps aux | grep crond Cron will sent a mail to root, if there are problems, so check root's mail Look in the logfiles to see if there is a problem with the mail. Kind regards |
Quote:
Code:
echo "du -s /home" > /home/username/scriptname |
Thanks to Kernl, Repo;
Oh man, I just follow your instructions and don't understand nothing. :confused: But for now, that is too much for me. :) I run the command: ps -ef | grep -e crond, I got 2 lines: root 15558 1 0 11:49 ? 00:00:00 crond root 18168 3427 0 14:29 tty1 00:00:00 grep -e crond that means the crond thing is working, right? I also changed the cron job as yours: */2 * * * * echo "testing" >>/tmp/foo.$$ Yes, I see somthing like: foo.17928 foo.17944 foo.18004 and so on ... I try looking for errors but there is no syslogs file in my system. Instead, I see a Cron file. I open it and see something like this: Oct 5 14:06:01 Legacy crond[17782]: (root) CMD (du -h /home | mail -s "testing" dan@gmail.com) Oct 5 14:06:01 Legacy crond[17780]: (root) MAIL (mailed 148 bytes of output but got status 0x004e ) Oct 5 14:06:01 Legacy crond[17779]: (root) MAIL (mailed 67 bytes of output but got status 0x004e ) Oct 5 14:08:01 Legacy crond[17835]: (root) CMD (du -h /home) Oct 5 14:08:01 Legacy crond[17834]: (root) MAIL (mailed 148 bytes of output but got status 0x004e ) Oct 5 14:09:01 Legacy crond[17846]: (root) CMD (du -h /home | mail -s "testing" dan@gmail.com) Oct 5 14:09:01 Legacy crond[17845]: (root) MAIL (mailed 67 bytes of output but got status 0x004e ) Oct 5 14:10:01 Legacy crond[17860]: (root) CMD (du -h /home) Oct 5 14:10:01 Legacy crond[17859]: (root) MAIL (mailed 148 bytes of output but got status 0x004e ) Oct 5 14:12:01 Legacy crond[17875]: (root) CMD (du -h /home | mail -s "testing" dan@gmail.com) Oct 5 14:12:01 Legacy crond[17876]: (root) CMD (du -h /home) Oct 5 14:12:01 Legacy crond[17874]: (root) MAIL (mailed 148 bytes of output but got status 0x004e ) Oct 5 14:12:01 Legacy crond[17873]: (root) MAIL (mailed 67 bytes of output but got status 0x004e ) I'm using CentOS distro in AsteriskNow. there is no GUI at all but a black sreen for command lines. Thank you very much for your help, Best Regards, |
Your cron is working, your mail isn't.
Make sure sendmail is setup correctly. What happens if you type Code:
du -h /home | mail -s "testing" dan@gmail.com What happens if you sent a mail to your gmail account? Look in the logfiles Do you have root access? Kind regards |
Thanks Repo,
I check my gmail account but nothing received. Quote:
Quote:
Best Regards, |
Quote:
Code:
du -h /home | mail -s "testing" root type Code:
mail Quote:
Kind regards |
Hi Repo,
Here are some msg in Maillog file: Oct 5 15:32:01 Legacy sendmail[19058]: NOQUEUE: SYSERR(root): can not chdir(/var/spool/clientmqueue/): No such file or directory Oct 5 15:32:01 Legacy sendmail[19059]: NOQUEUE: SYSERR(root): can not chdir(/var/spool/clientmqueue/): No such file or directory Oct 5 15:34:01 Legacy sendmail[19075]: NOQUEUE: SYSERR(root): can not chdir(/var/spool/clientmqueue/): No such file or directory Oct 5 15:34:01 Legacy sendmail[19076]: NOQUEUE: SYSERR(root): can not chdir(/var/spool/clientmqueue/): No such file or directory Oct 5 15:36:01 Legacy sendmail[19123]: NOQUEUE: SYSERR(root): can not chdir(/var/spool/clientmqueue/): No such file or directory Oct 5 15:36:01 Legacy sendmail[19124]: NOQUEUE: SYSERR(root): can not chdir(/var/spool/clientmqueue/): No such file or directory Oct 5 15:38:02 Legacy sendmail[19141]: NOQUEUE: SYSERR(root): can not chdir(/var/spool/clientmqueue/): No such file or directory Oct 5 15:38:02 Legacy sendmail[19142]: NOQUEUE: SYSERR(root): can not chdir(/var/spool/clientmqueue/): No such file or directory Oct 5 15:40:01 Legacy sendmail[19157]: NOQUEUE: SYSERR(root): can not chdir(/var/spool/clientmqueue/): No such file or directory Oct 5 15:40:01 Legacy sendmail[19158]: NOQUEUE: SYSERR(root): can not chdir(/var/spool/clientmqueue/): No such file or directory Oct 5 15:42:01 Legacy sendmail[19207]: NOQUEUE: SYSERR(root): can not chdir(/var/spool/clientmqueue/): No such file or directory Oct 5 15:42:01 Legacy sendmail[19208]: NOQUEUE: SYSERR(root): can not chdir(/var/spool/clientmqueue/): No such file or directory so, what's wrong with the email? How can I get it worked? Thank a million, Regards, |
Hi Repo,
I just figure out that there is no root mail in /var/spool. that is why I could not send email and run command <mail>, right? So, how can I setup a mail thing for send email? Thanks a lot, Best Regards, |
Try this:
Code:
mkdir /var/spool/clientmqueue Code:
yum reinstall sendmail sendmail-devel Kind regards |
All times are GMT -5. The time now is 01:19 PM. |