3

I've been trying to get the output of a cronjob to show in the terminal and I can't figure it out. Every minute I would like to run the script /usr/games/sl and have it output in the terminal, and I've tried a few different ways, mainly the ones in this post. I can't just write the output to a text file because the command moves across the screen, and it gives gibberish when viewed with tail or nano.

I have two different variations in the crontab file at the moment:

* * * * * /usr/games/sl > /dev/pts/2 2>&1

* * * * * /usr/games/sl > /dev/tty1 2>&1

The second one at least gives me an error, Error opening terminal: unknown. which I think is because I'm using tty1 and not pts/2. I don't really understand how terminals and all of that stuff work yet, so I am stuck at the moment. Does anyone have a suggestion on how I can view the cronjob in real time?

TL;DR Every minute I want the sl command to run on the screen and show the output. I tried with cronjobs and failed.

cutrightjm
  • 134
  • 11
  • 1
    It might help you get a better solution if you can give some more context into what you really want to accomplish. Using the right tools for the job is important, and there might be something other than cron that can do what you want. Cron is for running batch processes, typically on servers, whether or not anyone is logged in or using the machine, so there may not be an active terminal to display on. So are you asking about how to check on the status of a background job or do you want something to run repeatedly only when someone opens a terminal? – Michael Miller Jun 04 '14 at 18:03
  • @mtmiller every minute I want the sl command to run on the screen and show the output – cutrightjm Jun 04 '14 at 18:05
  • What's sl? .. – Braiam Jun 04 '14 at 18:14
  • @Braiam See #1 :) http://mylinuxbook.com/funny-side-of-linux-command-line/ – cutrightjm Jun 04 '14 at 18:16

2 Answers2

0

Have the commands output to a file from crontab and then tail -f the file to monitor the output.

  • Hi Joe, that doesn't work because the command moves across the screen. It is just a bunch of gibberish when done that way. – cutrightjm Jun 04 '14 at 18:50
  • I see, so you are saying that the command ONLY knows how to output to terminal? This, by definition, makes it unsuitable for cron. You might try the linux at command. – Joe Atzberger Jun 04 '14 at 19:01
  • Alright, I'll try that in the morning if I have time, I'll let you know how it works. Would a screen work, though? – cutrightjm Jun 04 '14 at 19:08
  • Are you asking about the GNU screen command? Screen is great, and certainly you could use screen to catch the at outputs in one tab (terminal) while still using the monitor for other work in other tabs. – Joe Atzberger Jun 04 '14 at 19:14
0

Crontasks run in their own shell. You can make the screen do what you want with a simple loop, but it will be dedicated to the task and interrupted by ctrl-c.

while sl;do sleep 1m;done

brad sanders
  • 271
  • 1
  • 4