Trying to write a bash script which will open a screen, start a python application, and interact with the python interaction as required when it is first started.
If not possible in screen, I would be happy to switch to tmux as an alternative. I am just not that great at bash scripting and have no experience with expect.
Here is what I have so far:
sent=blah
expexec=$(/usr/bin/expect -c "/usr/bin/python /opt/app.py expect \"Interaction:\" send \"$sent\r\" interact")
/usr/bin/screen -L -dmS spawner /bin/sleep 30
/bin/sleep 1
/usr/bin/screen -S spawner -X screen screen -L -dR myDaemon
/bin/sleep 1
/usr/bin/screen -S myDaemon -X detach
/usr/bin/screen -S myDaemon -X stuff "echo $expexec"
/usr/bin/screen -S spawner -X stuff "exit\r"
Hoping someone can help me…
Above is the latest iteration, where I have tried to write the entire command as seen in another example in a variable. The screen commands all work, but I can't get expect to correctly execute and look for the input queue and send the response.
Thanks in advance,
JG
Best Answer
Just in case this will help anyone else, I thought I would let everyone know how I got this working. I simply split my one script into two, with the expect portion in its own script. My version only makes use of one variable, but it is easily scalable I guess.
expect script:
main script:
JG