Sending commands to a process which runs inside screen
[The script screen-test.sh runs the secondary script]
NB: nothing gets output in the screen session window itself
- if you want that then use tee
2>&1 | tee $TMPFILE
cat screen-test.sh
#!/bin/sh
# Send command to screen session
# - if you have more than one screen session, you'll
# need to find out the right session and use it
# specifically.
#screen -r 10345.root -X exec ${PWD}/screen-test2.sh
screen -r -X exec ${PWD}/screen-test2.sh
# Give job time to complete before continuing....
sleep 1
# Get output file name (was created in other script with mktemp)
MYFILE=$(ls -rt /tmp/screen-test.*|tail -1)
# Display file and remove it
cat $MYFILE && rm $MYFILE
cat screen-test2.sh
#!/bin/sh
TMPFILE=$(mktemp -p /tmp screen-test.XXXXXX)
(
echo "+====+ $TMPFILE +====+"
echo "Running in dir: $(pwd)"
echo "-----------------------"
# command(s) to run in session to create desired output
/bin/ls
echo -e "======================="
) 2>&1 > $TMPFILE
found at https://lists.gnu.org/archive/html/screen-users/2011-04/msg00006.html
Comments
Post a Comment