0

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)"
Mister_L
  • 2,469
  • 6
  • 30
  • 64

1 Answers1

1

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

Amias
  • 335
  • 6
  • 16
  • you have to do the screen detach from an active session so that it has a tty and you have to use -dmS to do it – Amias Aug 09 '16 at 14:01