LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-05-2010, 02:44 PM   #1
DanStrong
LQ Newbie
 
Registered: Oct 2010
Location: California, USA
Distribution: CentOS
Posts: 20

Rep: Reputation: 0
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!
 
Old 10-05-2010, 03:00 PM   #2
kernl
LQ Newbie
 
Registered: Oct 2007
Distribution: Ubuntu/RedHat/Debian
Posts: 7

Rep: Reputation: 4
Quote:
Originally Posted by DanStrong View Post
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!
There could be a number of things wrong, including having a mail server to send the mail.

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.
 
1 members found this post helpful.
Old 10-05-2010, 03:14 PM   #3
DanStrong
LQ Newbie
 
Registered: Oct 2010
Location: California, USA
Distribution: CentOS
Posts: 20

Original Poster
Rep: Reputation: 0
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!
 
Old 10-05-2010, 03:56 PM   #4
DanStrong
LQ Newbie
 
Registered: Oct 2010
Location: California, USA
Distribution: CentOS
Posts: 20

Original Poster
Rep: Reputation: 0
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
 
Old 10-05-2010, 04:49 PM   #5
kernl
LQ Newbie
 
Registered: Oct 2007
Distribution: Ubuntu/RedHat/Debian
Posts: 7

Rep: Reputation: 4
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.
 
1 members found this post helpful.
Old 10-05-2010, 04:55 PM   #6
kernl
LQ Newbie
 
Registered: Oct 2007
Distribution: Ubuntu/RedHat/Debian
Posts: 7

Rep: Reputation: 4
Quote:
Originally Posted by DanStrong View Post
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!
By the way, you won't get anything with the echo command, because STOUT is discarded after the command is run. If you want to test cron, try this:
* * * * * 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
 
1 members found this post helpful.
Old 10-05-2010, 04:57 PM   #7
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
Quote:
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?
No, this is normal

First lets see if the cron daemon is running
Code:
ps aux | grep crond
then, take a look in the logfiles to see if there are any errormessages from cron.
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
 
1 members found this post helpful.
Old 10-05-2010, 05:00 PM   #8
joec@home
Member
 
Registered: Sep 2009
Location: Galveston Tx
Posts: 290

Rep: Reputation: 70
Quote:
Originally Posted by DanStrong View Post
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!
2 part answer. If cron is not responding then the password for the user may have expired. See if resetting the password for the user account fixes the cron issue. Also it is a common misconception that cron will run bash commands. Sometimes cron will operate in this fashion, but cron is in theory supposed to run scripts, not commands. You may try placing the commands as a script and run the script in cron.

Code:
echo "du -s /home" > /home/username/scriptname
chmod 700 /home/username/scriptname

Add */2 * * * * ./home/username/scriptname to cron
 
Old 10-05-2010, 05:51 PM   #9
DanStrong
LQ Newbie
 
Registered: Oct 2010
Location: California, USA
Distribution: CentOS
Posts: 20

Original Poster
Rep: Reputation: 0
Thanks to Kernl, Repo;
Oh man, I just follow your instructions and don't understand nothing. 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,
 
Old 10-05-2010, 06:03 PM   #10
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
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 send a mail to your username ?
What happens if you sent a mail to your gmail account?
Look in the logfiles
Do you have root access?

Kind regards

Last edited by repo; 10-05-2010 at 06:07 PM.
 
1 members found this post helpful.
Old 10-05-2010, 06:27 PM   #11
DanStrong
LQ Newbie
 
Registered: Oct 2010
Location: California, USA
Distribution: CentOS
Posts: 20

Original Poster
Rep: Reputation: 0
Thanks Repo,

I check my gmail account but nothing received.
Quote:
What happens if you send a mail to your username ?
Can I sent mail to root? Because I login as root account.
Quote:
Look in the logfiles
Do you have root access?
Could you show me how to do this?

Best Regards,
 
Old 10-05-2010, 06:34 PM   #12
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
Quote:
Can I sent mail to root? Because I login as root account.
Code:
du -h /home | mail -s "testing" root
To read roots mail
type
Code:
mail
or use pine or mutt

Quote:
Could you show me how to do this?
look in /var/log/maillog

Kind regards
 
1 members found this post helpful.
Old 10-05-2010, 06:47 PM   #13
DanStrong
LQ Newbie
 
Registered: Oct 2010
Location: California, USA
Distribution: CentOS
Posts: 20

Original Poster
Rep: Reputation: 0
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,
 
Old 10-05-2010, 07:05 PM   #14
DanStrong
LQ Newbie
 
Registered: Oct 2010
Location: California, USA
Distribution: CentOS
Posts: 20

Original Poster
Rep: Reputation: 0
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,
 
Old 10-06-2010, 02:44 AM   #15
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
Try this:
Code:
mkdir /var/spool/clientmqueue
chown smmsp:smmsp /var/spool/clientmqueue
chmod 770 /var/spool/clientmqueue
chmod 700 /var/spool/mqueue
chown root.root /var/spool/mqueue
chmod 777       /var/spool/mail
chown root.root /var/spool/mail
chmod 4555       /usr/sbin/sendmail
chown root.smmsp /usr/sbin/sendmail
Or reinstall sendmail
Code:
yum reinstall sendmail sendmail-devel

Kind regards

Last edited by repo; 10-06-2010 at 02:49 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Crontab is not working, the script is working arfal SUSE / openSUSE 6 02-08-2010 09:48 PM
Crontab is not working Ejdaha Linux - Newbie 15 12-01-2009 06:16 PM
Crontab Not working appropriate? roclok Linux - Software 9 06-16-2006 12:34 AM
crontab not working subaruwrx Linux - Newbie 8 08-17-2004 10:12 PM
Crontab not working Neorio *BSD 1 12-02-2003 08:34 PM


All times are GMT -5. The time now is 04:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration