I have three different executables to run in sequence, two of them are byte executables. I want to automatically run them in sequence. It requires user inputs also initially. How to automate this with a script? Can anyone redirect to some tutorial or examples?
-
http://stackoverflow.com/questions/4780893/use-expect-in-bash-script-to-provide-password-to-ssh-command – Andy Aug 18 '12 at 18:12
3 Answers
You can write a simple shell script for it.
Test.sh
#!/bin/sh
<Paste your commands>
Execute the code :
sh Test.sh

- 2,419
- 1
- 27
- 46
You're requirements are pretty vague. "I need stuff to execute in sequence some which require user input". Bash affords us a lot of flexibility for addressing these issues on a case by case basis but to really give you a GOOD answer we would probably want to know what the commands are and what inputs are required. Just want to execute commands in sequence? semicolons are for you
cmd1 ; cmd2; cmd3
Does it matter if one of the commands fails or should the second command only be executed upon successful completion of the first? If these exit codes matter you are probably better off using double &&
cmd1 && cmd2 && cmd3
A lot of times user inputs can be redirected into a program or specified within the command line using arguments for example:
{ echo "remotecommand 1" } | telnet localhost 1234
or
ssh -o StrictHostKeyChecking=no 192.168.1.1
Outside of that you are starting to require expect scripting. So you see there are many cases which can come up where automation is possible but without much to go on it's hard to give you a specific answer.

- 11
- 1