Is it possible to start a screen session, set up an cronjob, and redirect the cronjob's output to the screen session? Would be great to follow the programm's output ;-)

Greetings....

link|improve this question

60% accept rate
feedback

4 Answers

up vote 0 down vote accepted

You could use the tty command in that screen to find the path to it's tty (should be something like /dev/pts/12), and then in crontab redirect all output to that path as if it were a file.

Like this:

1 2 3 4 5 myapp &> /dev/pts/14
link|improve this answer
feedback

as radius mentioned, there's no sure way of knowing which tty or ttys your screen session will be using at any given moment....or even which of the many pseudo-ttys that might be open in screen is the one that you actually want the output sent to.

your best bet is to redirect the cron job's output (both stdout & stderr) to a file, and then run 'tail -f' or 'tail -F' on it from within screen. that gives you a permanent logfile as well as the ability to watch it in real-time.

alternatively, don't redirect the output at all and just wait for the job to finish - all output will then be mailed to the job's owner.

link|improve this answer
feedback

grawity give a good way to do that but the problem is that each time you restart screen/server the tty will change.
You may do a pipe to the write(1) command like | write user. This will send a message to user "user", you just need to have a window opened user this user in screen to see the output but write will add some message before the stdout value.

link|improve this answer
feedback

Why not just start screen in the cronjob, then start whatever it is you want to run inside that? screen -d -m <command to run> should do the trick.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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