0

How can I log the output of multiple screen sessions which are executed by crontab seperately? Currently I am running them in "screen -dm -L " style in crontab but it logs all the sessions to screenlog.0 file.

In relation to that, how shall I format the command line for crontab so that I can name each screen session?

0

If you take a look at the screen man page, you'll note that right under the -L option is the -Logfile option:

   -Logfile file
        By default logfile name is "screenlog.0". You can set new
        logfile name with the "-Logfile" option.

Setting that to a unique file for each cron task should get you what you want.

  • Thanks for the answer! Do you also know how I should name the sessions? I mean, what would be the correct syntax if I wanted to name each session run by Crontab differently? Also, out of curiosity, is it possible to name the log files parametrically with screen? (e.g. based on the date/hour) – GunG Oct 28 '18 at 14:35
  • I think you should name the sessions whatever you want. I don't know what you're doing so I don't have any suggestions. I don't think screen has any support for parametric naming of files, but since cron tasks are executed by a shell you should just do something like -Logfile /path/to/my/log-$(date +%Y-%m-%d).log to interpolate the date into the filename. – larsks Oct 28 '18 at 15:33
  • Thanks again for the answer, what I meant to ask was, if I wanted to name it from the crontab, should the correct syntax for crontab be "screen -dm -Logfile /path/to/my/log-$(date +%Y-%m-%d).log -S name_for_session command_to_run" – GunG Oct 28 '18 at 16:46
  • That looks reasonable. What happens if you try it? – larsks Oct 28 '18 at 17:54
  • For some reason I haven't figured out, the Ubuntu 16.04.5 LTS instance keeps giving an error "Error: Unknown option Logfile" – GunG Nov 7 '18 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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