Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant start linux "screen" with logging to specific output file

Tags:

gnu-screen

I have the problem that I want to enable logging of a screen session at the start of it which then saves the log to a specific file. What I have until now was:

screen -AmdSL cod2war /home/cod2server/scripts/service_28969.sh

while service_28969.sh is a shell script that will call other scripts which produce output. I started multiple of those screen-sessions with different names, for example

screen -AmdSL cod2sd /home/cod2server/scripts/service_28962.sh

-L enables logging as the screen's man say, and will safe the ouput in a file called 'screenlog.0', now since I have multiple of those screens only one of it produces output saved in that log file (I can't find other 'screenlog.*' files in that folder).

I thought to use the -Logfile "file" option from the same man page, but it doesn't work for me and I can't find out what I'm doing wrong..

screen -Logfile cod2sd.log -AmdS cod2sd /home/u268450/cod2server/scripts/service_28962.sh

will produce the following error:

Use: screen [-opts] [cmd [args]]
 or: screen -r [host.tty]

Options:
[...]
Error: Unknown option Logfile

and

screen -AmdS cod2sd /home/u268450/cod2server/scripts/service_28962.sh -Logfile cod2sd.log

will run without any error and start the screen but without the logging at all..

like image 959
Tom Avatar asked Oct 24 '25 02:10

Tom


2 Answers

I just ran into this error myself and found this solution that worked with my python file, wanted to share for anyone else who might run into this issue:

screen -L -Logfile LOGFILENAME.LOG -dmS SCREENNAME python3 ./FILENAME.PY

I have no idea if this is the 'correct' way but it works.

-L enables logging

-Logfile LOGFILENAME.LOG declares what to call the log file and file format

-dmS SCREENNAME, dm runs in detached mode and S allows you to name the session

python3 ./FILENAME.PY in this case is my script but I assume that any other script here functions

I have tried a different ordering of these commands and this was the only way I managed to have them all run without issues. Hopes this helps.

like image 70
Mazen Mirza Avatar answered Oct 26 '25 22:10

Mazen Mirza


You can specify a logfile from within the default startup ~/.screenrc file using a line like

logfile mylog.log

To do this from the command line you can create a file mystartup to hold the above line, then use option -c mystartup to tell screen to read this file for setup instead of the default. If you also need to have ~/.screenrc read, you can add the source command to your startup file. The final result would look something like:

echo 'logfile mylog.log
source ~/.screenrc' >mystartup
screen -AmdSL cod2war -c mystartup /home/cod2server/scripts/service_28969.sh
like image 44
meuh Avatar answered Oct 26 '25 23:10

meuh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!