Re: Sending commands to a process which runs inside screen

Andrew McGlashan <andrew.mcglashan-eCNwZfdMfp8leAitJ8REmSkBLnlaf3ui@public.gmane.org>
Newsgroups gmane.comp.gnu.screen.user
Organization Affinity Vision Australia Pty Ltd
Message-ID <[email protected]>
Hi,

Stefan Kuhlemann wrote:
> I'm looking for a solution for a problem which keeps nagging me for
> quite some time...

This might help.

[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





-- 
Kind Regards
AndrewM

Andrew McGlashan
Broadband Solutions now including VoIP
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.