LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-13-2008, 07:15 AM   #1
vickylife
LQ Newbie
 
Registered: Nov 2008
Posts: 6

Rep: Reputation: 0
How to run a set of commands through ssh


I need to run a set of commands on a remote machine using ssh. it should also collect output and return status of each command. Can someone help me how to do this?
 
Old 11-13-2008, 07:23 AM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Not a problem.

Something like
Code:
ssh user@remote 'command; command2; command3' > remote-output
You'll end up with a file 'remote-output' with the output from the commands.

Dave
 
Old 11-13-2008, 07:23 AM   #3
mrclisdue
Senior Member
 
Registered: Dec 2005
Distribution: Slackware
Posts: 1,134

Rep: Reputation: 277Reputation: 277Reputation: 277
This is homework....
 
Old 11-13-2008, 07:32 AM   #4
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hmmm. Yeah, you may well be right. Looks like my homework detector has run out of juju.

Good job I didn't answer all of the question, really.

Last edited by ilikejam; 11-13-2008 at 07:33 AM.
 
Old 11-13-2008, 07:54 AM   #5
vickylife
LQ Newbie
 
Registered: Nov 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks ilikejam. However my commands are related. That is i should be running command 2 only when command one is successful.
 
Old 11-13-2008, 08:27 AM   #6
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
What commands are you supposed to be running?
 
Old 11-13-2008, 09:09 AM   #7
martina
LQ Newbie
 
Registered: Nov 2008
Distribution: SLES
Posts: 2

Rep: Reputation: 0
in bash, you can just say 'set -e; command1; command2; command3;'
it will stop on a bad return code and return it to where you are calling it from.
 
Old 11-13-2008, 11:17 AM   #8
vickylife
LQ Newbie
 
Registered: Nov 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ilikejam View Post
What commands are you supposed to be running?
i have to add few package in client machine in solaris. Before that i have to check if these packages also exist in server. So before installing on client first i will execute these three commands on server remotely(using ssh)
pkginfo SUNWabc
pkginfo SUNWpgr
pkginfo SUNWxyz

So say if the first package itself is not installed, i wont look for others and directly quit with an error message
 
Old 11-13-2008, 06:48 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Adjusting ilikejam's code to match new requirement:
Code:
ssh user@remote 'command && command2 && command3' > remote-output
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to set redirect for all commands hillpigLQ Linux - Newbie 1 09-19-2008 05:51 AM
getting SSH commands to run as local r00tb33r Linux - Software 2 02-02-2008 11:58 PM
Log all SSH commands at ssh-client. mohammednv Linux - Networking 6 01-26-2008 05:02 AM
ssh connection refused - trying to set up ssh server at home openSauce Linux - Server 10 10-18-2007 04:38 PM
LXer: Run Parallel Commands in a Cluster Using SSH on UNIX LXer Syndicated Linux News 0 09-12-2006 01:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration