You are not logged in.
Pages: 1
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
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.
Cheers!
Offline
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
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)
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
[
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
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
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
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
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
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
Pages: 1