Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 05-22-2009, 04:44 AM   #1
Registered: Feb 2006
Location: Bangalore, India
Distribution: Fedora Core 3
Posts: 68

Rep: Reputation: 15
Crontab doesn't give the output of the file it runs in terminal

I have scheduled a shell script to run at a particular time of day using 'crontab'.
# crontab -l
30 22 * * 5 /bin/su root -c "/"  
However, the echo commands output are not displayed on the terminal window when the script executes. I tried setting the crontab in the following manner,
# crontab -l
30 22 * * 5 /bin/su root -c "/"> /dev/stdout  

But still I do not see the output on the screen. How can get the output of a script run by 'cron' on terminal screen ?

Last edited by pranavojha; 05-22-2009 at 04:46 AM.
Old 05-23-2009, 12:50 PM   #2
LQ 5k Club
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Cron normally sends you mail if a cron task generated any output (this
should include error messages).
You could redirect the output to a logfile.
Old 05-23-2009, 01:11 PM   #3
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
To get the output in a terminal, you have to explicitly open it from the cron job and launch the script as a terminal command. Using KDE I can do something like:
10 19 * * * env DISPLAY=:0.0 konsole --noclose -e echo hello world
note that you have to set the DISPLAY environment variable, otherwise cron does not know where to open a new terminal. Furtehrmore the user to which the crontab belongs, must have an X session open (take in mind you cannot connect to the X display of another user, since usually you don't have the right permissions).

Finally, you have to find a way to keep the terminal open after the command execution. In konsole, as you can see from my example, there is a --noclose option. You have to find the trick if you use another terminal.
Old 08-24-2013, 05:19 PM   #4
LQ Newbie
Registered: Dec 2012
Posts: 1

Rep: Reputation: Disabled

Thanks for that answer. An update for any debian users (I'm using Mint15 but Ubuntu etc should be the same).

I am using rdiffbackup so call a script that drives it. My command line is:

04 07 * * * env DISPLAY=:0.0 gnome-terminal -e /home/of user/.rdiffbackup

With gnome-terminal you can choose behaviour of the terminal when the command finishes. In my case I wanted the terminal to disappear if all backups complete successfully so I didn't. Instead I use the read command after an error to pause the terminal, awaiting user input.

A note for any rdiffbackup users having issues with cron. Cron has a very limited user environment compared with your terminal so you may have to fill in some missing variables for the SSH to work for rdiffbackup. In my case I needed to fill in SSH_AGENT_PID and SSH_AUTH_SOCK - the code is for the fish shell ... substituted " for the brackets around the command if you're using bash. The second assumes that the folder *keyring-* and associated file *ssh* is within /run - if its not then find out where your distro hides it and change it (the originator of this idea was searching /tmp for it).

set -x SSH_AGENT_PID (ps axww | grep -v grep | grep ssh-agent | grep -o -e [0-9][0-9][0-9][0-9])

set -x SSH_AUTH_SOCK (find /run/ -path '*keyring-*' -name '*ssh*' -print 2>/dev/null)
I include this in an old thread because google only cares about hit counts

Last edited by kiwi9; 08-24-2013 at 05:30 PM.


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
Strange output log of crontab kuangchen Linux - Newbie 1 05-30-2008 05:13 AM
crontab runs and stops in middle of process. Strange! Micro420 Linux - General 2 03-28-2007 03:46 AM
Redirect terminal output to file AND terminal shan Linux - General 3 09-29-2006 09:36 AM
How to direct output both log file and to terminal... freebies Linux - General 1 02-25-2005 07:32 AM
C++ prorgam runs OK from command line, but failed from crontab vgolden Linux - Software 2 01-21-2005 12:00 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:43 PM.

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