LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-08-2007, 03:46 PM   #1
Corrado
Member
 
Registered: Aug 2004
Location: Washington
Distribution: RHEL 5.0
Posts: 153

Rep: Reputation: 16
Many commands using ssh


I would like to run more than one command on a system using remote ssh.
I wish to only be prompted once for password.

Is there any way to do this in ssh?

Chris

Last edited by Corrado; 05-08-2007 at 07:47 PM.
 
Old 05-08-2007, 04:23 PM   #2
sydney-troz
Member
 
Registered: Feb 2007
Distribution: Kubuntu, it's obese barely-usable sibling, Ubuntu
Posts: 142

Rep: Reputation: 15
I assume you mean running multiple commands from a script, and not interactively.
 
Old 05-08-2007, 07:46 PM   #3
Corrado
Member
 
Registered: Aug 2004
Location: Washington
Distribution: RHEL 5.0
Posts: 153

Original Poster
Rep: Reputation: 16
Yes, from a script.
 
Old 05-08-2007, 10:44 PM   #4
DeuceNegative
LQ Newbie
 
Registered: May 2006
Location: Boston, MA
Distribution: Gentoo
Posts: 29

Rep: Reputation: 16
You can compose commands together with ``;'' and quote the whole thing so ssh treats it as one thing:

Code:
ssh some.where.com 'command1; command2; command3'
Obviously, it can get quite complicated if the arguments to the commands themselves need quotation marks in them, but it's doable. (It's especially complicated because you effectively have to double escape/quote things, since what ssh gets is run as if you wrote on the command line on the remote server.)

Note that one of those commands could be something like a wget that downloads your shell script from somewhere, and the other command(s) run it.

When I have a whole bunch of stuff to accomplish, and I don't want to do the wget thing, and I know the remote machine has python, I convert my set of commands to python code, write it in hex digits, and use something like this:

Code:
ssh some.where.com python -c 'exec\(\"\\x74\\x72\\x79\\x3a... ...\\x0a\"\)'
That looks crazy, but of course I don't do that by hand, I write a little python code to do the conversion. Then I know I've avoided all of the shell escape character issues, and I can run arbitrary code. However, the command does get huge fast. Maybe the same thing can be done with just shell code, I don't know. Usually it's python I want to execute anyways.

Hope that helps.
 
Old 05-10-2007, 01:05 AM   #5
Corrado
Member
 
Registered: Aug 2004
Location: Washington
Distribution: RHEL 5.0
Posts: 153

Original Poster
Rep: Reputation: 16
Thank you. This will help very much.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Python commands over ssh Kedelfor Programming 7 10-18-2005 04:07 AM
Passing commands via ssh Comatose51 Linux - Security 1 04-13-2005 04:31 PM
Running commands over ssh iago Programming 8 11-28-2004 12:13 PM
executing multiple commands by ssh jpan Linux - General 1 10-22-2004 02:12 PM
SSH login commands not found ??? avierstr Mandriva 0 08-26-2003 07:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:04 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration