I have created a screen, but can I now somehow execute a command that will run commands in the detached screen?
I do not even know if this is possible, but if it is, it will probably be something simple and easy for you.
Thank you for your effort.
Note: The original poster asked 'how can i do this in cron'. I've updated the response to address that.
Get the 'inscreen' script and put it in ~/bin/
:
# download 'inscreen' script from https://gist.github.com/1019125 wget -O ~/bin/inscreen https://gist.github.com/gists/1019125/download chmod 755 ~/bin/inscreen
create a screen session named 'cronjobs':
screen -d -m -S cronjobs
You'll have to arrange for that to happen on each boot, or add '--new-if-needed' to each crontab entry below.
Add entries in cron using inscreen
, crontab looks like:
PATH = /home/YOURNAME/bin:/usr/sbin:/usr/bin:/sbin:/bin * * * * * inscreen cronjobs -- sh -c 'echo $(date): start; sleep 30; echo $(date): end; sleep 4' 0 0 * * 0 inscreen cronjobs --keep-open --title reminder echo ==== CALL YOUR MOM ==== 0 0 * * 1 inscreen cronjobs --window 0 ls /tmp
The above will:
smoser's answer is good though a little complex. You can also just simplify this to just
screen -d -m -S mysession -t label sleep 1m
with the caveat that, when the process exits, the screen will just disappear, and you won't be able to see what it wrote to the screen. That might or might not be ok for your case. You can change that by setting in your .screenrc
defzombie ZZ
which will mean that screens hang around after their process exits until you press Z.