0

I am a newbie in shell scripting and want to use the screen command to automate the below scenario:

  1. Create a screen session1 and execute a shell script1
  2. create another screen session2 and execute another shell script2, and if this result is success then go to screen session1 and resume the script1 there by pressing enter.

Is this possible using screen? please help with your suggestions how this can be done.

2 Answers 2

0

It might be possible, but I've no idea why you'd want to do it that way.

It all depends whether this is an attempt to automate existing scripts, or if this something you've written from scratch - or the architecture of a new product entirely?

If it's the former, I'd say it'd be easier to edit the existing scripts (are you sure they're actually scripts?) to not wait like that, or integrate the logic from one into the other.

If it's the latter, then you're doing it wrong, and should be using some other mechanism of IPC (Inter-Process communication) that doesn't involve keypresses.

1
  • Thanks Tom for answering the question, for me the case I is there where I have the existing scripts. But I can't change the logic therein since script1 has to wait until the second script gets executed...can this be done using screen or should I search more on this?
    – shelly
    Jun 21, 2013 at 7:08
0

You can use screen -X stuff '\n' to send a line feed to a running screen session.

I'd write a wrapper script that starts script2and sends a line feed to session1 if the script terminates successfully:

#!/bin/bash
./script2 && screen -S session1 -X stuff '\n'

The follwing two commands would now do what you want:

screen -S session1 -d -m ./script1
screen -S session2 ./wrapper
4
  • I tried this but how can I be sure that the line feed was received by script1 or may be how can I go and check whats going on on session1 i.e. script1 works as expected and is proceeding further after line feed
    – shelly
    Jun 21, 2013 at 7:51
  • You can attach to your screen session at any time: screen -r session1. Also, don't forget man screen.
    – Oliver
    Jun 21, 2013 at 8:22
  • I tried the command "screen -S session1 -d -m ./script1" but it doesn't add the screen and gives "cannot exec "session1" No such file or directory.However, if I tried adding screen manually with screen command it works.
    – shelly
    Jun 21, 2013 at 11:10
  • I have version 4.01.00devel (GNU) 2-May-06 of the screen utility. I can't help you any more than that. I'm afraid you need to do some basic troubleshooting yourself...
    – Oliver
    Jun 21, 2013 at 13:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .