I have a crontab that runs like this:
0 0 * * * /execute/shell/script.sh
0 0 * * * /execute/shell/script1.sh
0 0 * * * /execute/shell/script2.sh
And, I want to launch each script in a different screen. But I want to keep that screen running so that anytime I want to see the progress of one of these scripts, I can always just do screen -d -r <PID>
and it will reattach the screen for me to ssee the progress.
I'm sure there must be a way to do this. but the similar questions i've found have not answered it.
Crontab start a screen
How do I use crontab to start a screen session?
Best Answer
Do you actually have to interact with the commands, or do you just want to see the status before the commands complete, and the results are mailed back to you?
I've encountered a similar "issue", where I was running
traceroute(8)
andmtr
from within cron, to monitor connectivity, withmtr
running in afor
-loop to provide more precise measurements over a given interval (between 5 and 16.67 minutes (300 to 1000 cycles)), but the whole script designed to run for about an hour (to ensure I don't get spammed with emails), so, I wanted to be able to see the status as it happened.https://unix.stackexchange.com/questions/61820/how-can-i-access-a-deleted-open-file-on-linux-output-of-a-running-crontab-task
The way
cron
works is it creates a temporary file in /tmp, and immediately callsunlink(2)
(but still keeping the file open); this is subsequently used to store the output of your scripts before they finish, and it gets emailed to you.As such, you can use
lsof -n -c cron
(and/orlsof -n | fgrep cron
) to find out the number of open files that have been deleted, and then access those files via the/proc/$PID/fd/$FD
namespace to see the output of your scripts running from within cron, without any need forscreen
.