[英]linux can't access screens on crontab
I have created a bash file that executes a python script on an existing screen called 'cronscreen'. 我创建了一个bash文件,该文件在名为“ cronscreen”的现有屏幕上执行python脚本。 The bash file contains the following line: bash文件包含以下行:
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'. 当我从命令行运行文件时,它运行良好,并且在附加“ cronscreen”时看到输出已打印。 However, I would like it to run in cron, so I have set up crontab as follows: 但是,我希望它在cron中运行,因此我将crontab设置如下:
* * * * * 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). 执行cron是因为我可以看到每分钟都会重新生成文件agg.log,但是当我附加“ cronscreen”时,我看不到任何输出(并且agg.log为空)。 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. 屏幕需要一个tty active来创建会话,而该会话在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 您需要将其分为两部分,第一部分是运行屏幕并使它分离-screen -dmS cronscreen,然后在您的cronjob中使用-r cronscreen附加到屏幕会话
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.