简体   繁体   中英

linux can't access screens on crontab

I have created a bash file that executes a python script on an existing screen called 'cronscreen'. The bash file contains the following line:

screen -S cronscreen -X stuff "python test.py$(printf \\r)"

When I run the file from the command line, it works fine, and I see the output is printed when I attach my 'cronscreen'. However, I would like it to run in cron, so I have set up crontab as follows:

* * * * * myuser /home/myuser/myscript.sh > /home/ec2-user/agg.log

The cron is executed because I can see that the file agg.log is regenerated every minute, but when I attach 'cronscreen', I see no output printed there (and agg.log is empty). Why is that? Thanks.

Update:

I also tried changing the script to this(re-attaching the screen), but no change:

screen -r cronscreen
screen -S cronscreen -X stuff "python test.py$(printf \\r)"

screen needs an tty active to create a session which is not what is available under cron.

You need to split this into two parts , the first is to run screen and make it detach - screen -dmS cronscreen and then in your cronjob attach to the screen session with -r cronscreen

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM