You are not logged in.

#1 2010-12-05 05:41:09

LMW
Member
From: Las Vegas, NV
Registered: 2010-12-05
Posts: 8

Crontab doesn't work

Hi!

I've got following strings in crontab:

00 20 * * *  /home/user/script.sh 2>&1 > /dev/null
0-59 * * * * /bin/date

However, both of them doesn't work. There's no output in terminal for second string.

Here's what /var/log/crond.log shows (for "date", for example):

Dec  4 20:37:01 localhost crond[12029]: FILE /var/spool/cron/user USER user PID 12101 /bin/date
Dec  4 20:37:01 localhost crond[12102]: mailing cron output for user user /bin/date
Dec  4 20:37:01 localhost crond[12102]: unable to exec /usr/sbin/sendmail: cron output for user user /bin/date to /dev/null

As far as I know, sendmail can't cause these problems. In my case, it just won't send e-mail notification about completed job.

I've also tried to add PATH and SHELL par-rs, but with no success.

PATH=/usr/bin:/usr/sbin:/bin:/sbin
SHELL=/bin/sh

What can cause such problem?

Last edited by LMW (2010-12-05 05:41:49)


Bill Gates is a very rich man today... and do you want to know why? The answer is one word: versions. (c)

Offline

#2 2010-12-05 07:53:53

Vain
Member
Registered: 2008-10-19
Posts: 179
Website

Re: Crontab doesn't work

Hi,

that's because cron isn't attached to a terminal. Usually, it'll mail you any output — hence the need for sendmail or another MTA.

Try redirecting the output to a file:

*/1 * * * * /bin/date > /tmp/test

By the way, the log file says that your job ran. So, well, it works. wink

Cheers!

Offline

#3 2010-12-05 08:29:44

LMW
Member
From: Las Vegas, NV
Registered: 2010-12-05
Posts: 8

Re: Crontab doesn't work

Hello and thank you for reply.

Yes, if I redirect output to file, it works.

But what do I need to do to "attach cron to a terminal"? What does that mean?


Bill Gates is a very rich man today... and do you want to know why? The answer is one word: versions. (c)

Offline

#4 2010-12-05 08:33:34

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,217
Website

Re: Crontab doesn't work

LMW wrote:

But what do I need to do to "attach cron to a terminal"? What does that mean?

You can't -- it has it's own virtual terminal, which is what it emails to you if there is any output.

You could redirect it to say /dev/console (instead of /tmp/test) but that will go to the physical terminal so probably not what you want.

What is the problem you are trying to solve that you want output to your terminal? (EDIT: that's the point of cron... It runs tasks on a schedule, without the need for you to login)

Last edited by fukawi2 (2010-12-05 08:34:14)

Offline

#5 2010-12-05 08:40:00

LMW
Member
From: Las Vegas, NV
Registered: 2010-12-05
Posts: 8

Re: Crontab doesn't work

fukawi2 wrote:

[
You can't -- it has it's own virtual terminal, which is what it emails to you if there is any output.

You could redirect it to say /dev/console (instead of /tmp/test) but that will go to the physical terminal so probably not what you want.

What is the problem you are trying to solve that you want output to your terminal? (EDIT: that's the point of cron... It runs tasks on a schedule, without the need for you to login)

Well, I just want it to work as it should. I'd like to see output in my terminal. I suppose I need to install MTA to see output. Is it right?

Also, scripts still don't work even with output redirection:

00 20 * * *  /home/user/script.sh > /path/to/outputfile

Last edited by LMW (2010-12-05 08:41:48)


Bill Gates is a very rich man today... and do you want to know why? The answer is one word: versions. (c)

Offline

#6 2010-12-05 10:32:04

koomi
Member
Registered: 2010-09-26
Posts: 17

Re: Crontab doesn't work

Cron does work like it should, its not supposed to give you any output in a terminal, hence the sendmail. You could also pipe the output into the statusbar of your window manager or similar.
Alternatively, you could run an endless loop with sleep at the end of the loop in a terminal.
Or modify your shell prompt to display the date.

Can you execute the script manually without cron? Does it output anything?

Offline

#7 2010-12-05 17:59:36

LMW
Member
From: Las Vegas, NV
Registered: 2010-12-05
Posts: 8

Re: Crontab doesn't work

koomi wrote:

Cron does work like it should, its not supposed to give you any output in a terminal, hence the sendmail. You could also pipe the output into the statusbar of your window manager or similar.
Alternatively, you could run an endless loop with sleep at the end of the loop in a terminal.
Or modify your shell prompt to display the date.

Can you execute the script manually without cron? Does it output anything?

Yes, scripts are working well outside of cron. However, they doesn't work at all in crontab.


Bill Gates is a very rich man today... and do you want to know why? The answer is one word: versions. (c)

Offline

#8 2010-12-05 19:01:06

LMW
Member
From: Las Vegas, NV
Registered: 2010-12-05
Posts: 8

Re: Crontab doesn't work

I've managed to solve this issue. It was a problem with commands execution permissions in script. I've added "sudo" before each command (e.g. sudo rsync) and it works well now. Then, I've added absolute paths to these programs in /etc/sudoers for current user (to ignore root password every time program executes). Don't know if it's the way it's meant to work, but I don't see any other way. Any comments?


Bill Gates is a very rich man today... and do you want to know why? The answer is one word: versions. (c)

Offline

#9 2010-12-05 19:26:08

skunktrader
Member
From: Brisbane, Australia
Registered: 2010-02-14
Posts: 1,538

Re: Crontab doesn't work

Add the commands to root's crontab instead of your own if you have permission problems

Last edited by skunktrader (2010-12-05 22:46:53)

Offline

#10 2010-12-06 08:15:08

LMW
Member
From: Las Vegas, NV
Registered: 2010-12-05
Posts: 8

Re: Crontab doesn't work

skunktrader wrote:

Add the commands to root's crontab instead of your own if you have permission problems

Thank you for advice, I will take it into consideration. However, it works well right now.


Bill Gates is a very rich man today... and do you want to know why? The answer is one word: versions. (c)

Offline

Board footer

Powered by FluxBB