0

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....

Max
  • 465
  • 2
  • 6
  • 11

4 Answers4

1

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
user1686
  • 10,162
  • 1
  • 26
  • 42
1

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.

radius
  • 9,633
  • 25
  • 45
1

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.

womble
  • 96,255
  • 29
  • 175
  • 230
1

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.

cas
  • 6,783
  • 32
  • 35