Recently i was presented with the challenge of executing commands against a running program. This program was already running inside screen so it seemed natural to me to do some screen scripting. To my surprise i failed to find anything straight forward that explained how this could work. So here is my take on it in hopes that it helps someone else or myself if I forget it lol.
The simplest form is:
1
| |
This works for lots of things, here is a more complex call:
1
| |
This opens irb, types 2+5, executes it and exits irb.
Lets break its parts down:
screenduh-S testuse a running screen session named test-X stuff "irb^M2+5^M^D"push the string argument as input to screen- ^M new line
- ^D control + d
Using this method you can script anything that you had to do manually before.
Let me know if you know of another/better way.
Play Code
Create a new directory, cd into it and create a new executable file with the following content.
Gotcha: To automate everyting I had to sleep a few times. Not sure how to get around that yet.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |