Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a program that prints some output that I would like to pop up on my terminal once every hour during the workday.

$ crontab -l
0 07-17 * * * /home/dat/scripts/cron.out

syslog reports the following:

(dat) CMD (/home/dat/scripts/cron.exe)
Jun 18 12:02:01 picard CRON[10848]: (CRON) info (No MTA installed, discarding output)

What am I missing?

share|improve this question
    
cron jobs are not supposed to write to a terminal - there might be none available. –  guntbert Jun 18 '13 at 19:55

2 Answers 2

Cron emails you your script's output. Unfortunately, Ubuntu does not set up local mail by default, which is why Cron tells you in the logs “No MTA installed, discarding output”.

Setting up local mail could be one way to solve your problem. Instead of a output in a terminal, you'd get an email notification.

If you want your cron job to output to a terminal, you'll have to redirect its output to the terminal. The redirection part is easy —

0 07-17 * * * /home/dat/scripts/cron.out >/dev/pts/42 2>&1

but the problem is figuring out which terminal to redirect to. There's no universal answer to that, it depends how you want to select the terminal among the ones you're logged into.

For typical uses, a GUI notification would be more appropriate. You can use notify-send. You'll need to set the DISPLAY environment variable.

0 07-17 * * * DISPLAY=:0 notify-send "$(/home/dat/scripts/cron.out)"
share|improve this answer

The dirty way could be to redirect the output of your program to the pts file of an already existing terminal.

To know the pts file just type tty command

~$ tty
/dev/pts/4

then your crontab would be:

0 07-17 * * * /home/dat/scripts/cron.out > /dev/pts/4

Another way could be to launch the program as an argument of the terminal:

xfce4-termianl --command=/home/dat/scripts/cron.out --display=:0.0 -H

where display is the X display where you want to show the terminal, -H is to tell the terminal to stay open after the command is terminated. This will create every time a new terminal.

crontab:

0 07-17 * * * /usr/bin/xfce4-terminal --display=:0.0 -H --command=/home/dat/scripts/cron.out

if the display is not present you will have an error logged by syslog.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.