I have around 20 commands and I have to send all of this to Unix shell and copy the result, but I don't know how to do it.

I am not sure about what shell I have, because it is a small program connected to Mobile Network Managment, and with this small program we have access to send commands by line and recive the results by scream, for that reason I cannot use scripts for sending the commmands.

Command 1 - Connect with a server.

Wait until command 1 finish

Command 2- Update all the information from server 1 finish


Command 3. Get some parameter.

... and more such commands.

I tried with cmd1 | cmd2 | cmd3 and cmd1 & cmd2 & cmd3 and cmd1;cmd2

The problem is with cmd1 its connected to a RNC(Network element) and takes aroud 15 seconds, after that cmd2 has sense. but just work for the first cmd. Any clue, how to run this?

closed as unclear what you're asking by G-Man, countermode, Raphael Ahrens, Satō Katsura, phk Jun 13 '17 at 11:10

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    Use a script? Or && between commands. – Bernhard Feb 4 '13 at 13:00

Usually just cmd1;cmd2;cmd3;cmd4 (if you wanted to write it on one line), or using cmd1 && cmd2 && cmd3 && cmd4 if you don't want to run cmd3 when cmd2 fails.

Alternatively to ; you can just write one command per line.


If you want the commands to run in parallel in background, you can also use

cmd1 &
cmd2 &
cmd3 &
cmd4 &
wait # for cmd1-4 to finish

Either of those methods can also be put in a shell script. There is little difference between what you write in a shell script and what you write in the actual shell itself.

  • MM the problem its when I send cmd1 it really have to finish around 6 seconds, the problem its when it send cmd2 and cmd1 its still procesing it fails. – Jonathan Raul Tapia Lopez Feb 4 '13 at 16:34
  • 4
    In the cmd1;cmd2 case (or cmd1 && cmd2 for that matter) cmd2 won't run until cmd1 has exited (and thus presumably finished). So there should not be any problem - please rephrase your question, or provide an example that people can actually reproduce. – frostschutz Feb 4 '13 at 17:32
  • Ok I am gonna modify the question. thanks – Jonathan Raul Tapia Lopez Feb 5 '13 at 8:29

You may want to look into sleep, if your environment allows it. The complete sequence would then be something like cmd1 && sleep 10s && cmd2.
Here is the relevant man page for sleep.

  • sleep/waiting is only useful if you deterministically know how long the previous program (which might spawn backgrounded process) takes to finish and exit (IE The Halting Problem) OR if you guarantee that you want to interrupt and run your second command after the interval has passed, which might happen if the two are asynchronous but you still want to some time in between them. Most likely though, its not what you want. Practically speaking, it might work. But it's not reliable. – Justin Reeves Dec 21 '17 at 18:12

Just use a script, a file containing the commands to run one after the other, like:



The first line (shebang) tells to run the following commands using /bin/sh, make the file executable (chmod u+x your-little-script) then you can run it by ./my-little-script. This way you won't leave some step out ;-)

Read the manual for the shell, it provides a full programming language. Check out bash(1) if that is what is available, or else the Korn shell ksh(1). They offer lots of useful features for controlling the flow of control in scripts (or interactively, for that matter).

  • Thanks but I cant use scritps. – Jonathan Raul Tapia Lopez Feb 4 '13 at 16:24
  • Why? In any case, unless this is a very fascist environment, you should be able to source the script: source your-little-script (or . your-little-script for short). – vonbrand Feb 4 '13 at 16:58
  • Becuase, I havent directly access to the unix system I have like a mini program what just permite to execute cmd in lines and get the result by scream, and for the use Im gonna use with this commands its not practical to use scrips. – Jonathan Raul Tapia Lopez Feb 4 '13 at 17:22
  • OK, that clarifies things a bit... What environment is the origin/destination of your commands? What do you use to ship commands over to be executed? What is the remote environment? What is your setup there (do you have a regular account, that you can access via ssh or PuTTY perhaps? – vonbrand Feb 4 '13 at 17:46

You could run something like expect on your local computer to send cmd1 and wait for it to finish before issuing cmd2 etc. You have to figure out a reasonable period to wait, or a specific output which indicate that the command is done, in order to write a proper Expect script.

Of course, cmd1; cmd2; cmd3; cmd4 in one command will execute the commands in sequence, one after the other.

Not the answer you're looking for? Browse other questions tagged or ask your own question.