I would like to send a command to a screen session and if possible get the output.
My attempt at sending a command to a screen session is as I found on this website and lots of others, but it doesn't seem to work:
root@server [~]# screen -X "script -a -c 'ls -l' /tmp/command.log" && cat /tmp/command.log
cat: /tmp/command.log: No such file or directory
root@server [~]#
Note there is only 1 Screen session running, so I have omitted -S and -p (tried it with those too and no effect). For example:
root@server [~]# screen -p 0 -X stuff "script -a -c 'ls -l' /tmp/command.log" && cat /tmp/command.log
cat: /tmp/command.log: No such file or directory
stuff
, and you do need-p
. – Gilles 'SO- stop being evil' Dec 02 '12 at 23:43