简体   繁体   中英

How to run multiple programs in a sequence?

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?

Separate by semicolons for sequential execution:

cmd1 ; cmd2 ; cmd3

Separate by '&&' so that the next cmd runs only if the previous one succeeded:

cmd1 && cmd2 && cmd3

Here's a tutorial . See section 4.3.

You can write a simple shell script for it.

Test.sh

#!/bin/sh

<Paste your commands>

Execute the code :

sh Test.sh

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM