Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Hello 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 comands 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

Wait.

Command 3. Get some parameter.

... and more such commands.

I tryed 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?

share|improve this question
1  
Use a script? Or && between commands. –  Bernhard Feb 4 '13 at 13:00

4 Answers 4

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.

cmd1
cmd2
cmd3
cmd4

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.

share|improve this answer
    
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
1  
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.

share|improve this answer

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

#!/bin/sh

command-01
command-02
...
command-20

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).

Hope this helps.

share|improve this answer
    
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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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