Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I run multiple commands remotetly 1

Status
Not open for further replies.

fixengineer

Technical User
Apr 5, 2007
19
US
Korn-Shell on Sun/GNU Linux

I need to be able to run multiple commands romotetly. For example, from box1 run ls and pwd commands on box2.

This is what I tried:

ssh -l login boxname ls; pwd

With the above command grouping this is the result:

Command1=run ls on remote box
Command2=run pwd(locally)

I need:
Run commands1 and 2 on remote box.

Here is the idea. We have several servers that we need to go to all the time and it takes too much time login in and out of all the boxes and navigating around the directories. On top of that we have multiple windows open all the time so it's a big time consuming mess. I'm building a script that will produce a fake prompt and then mirror any command you type on the remote box. So basically anything you type will be run on the remote box. For every command the user types I want the script to login to box, go to a directory and run the users commands there. Problem is ssh will only allow one command at a time.

 
what about this ?
ssh -l login boxname 'ls; pwd'
or this ?
ssh -l login boxname ls\; pwd

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
dsh (Distributed Shell) is a very nice tool for your case!


If you want to run multiple commands on multiple hosts, first include the hosts in a file (newline-spearated)

Then do the following to that file (supposed its name is hello)

Code:
# export WCOLL=/hello
# dsh –r ssh 'df –k;ls'

This will run in all hosts that are located in the hello file! Very nice command!

Regards,
Khalid
 
Thank you very much!! Putting the commands in single quotes works! Now does anyone know how to make ssh stay on remote box after running command?

for example if you run:

ssh -l login boxname pwd

You will see pwd of remote box then end up on your local box, NOT still on remote box. I want to be able to send user to any box and then run command and leave them on the remotebox. I have no access to change anything on remote boxes. I can only write to local box.
 
do this:

ssh -l login boxname pwd; ssh -l login boxname

Regards,
Khalid
 
Thats great...and surprisingly simple. I should have got that one. Only thing is I need to stay on the box that I ran the command on, not go to box, run command, leave box, go to box.

Essentially I want my script to place user on box, in a certain directory for them to look at a certain log. I'm eliminating the need to navigate through the directories and to manually log into box.

Once my script establishes where you need to go(box and directory), I want it to take you there. Once the script is done it's job, all the user has to do is cat the log file that the script took you to. You should never have to use the cd command.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top