LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 06-18-2009, 02:27 PM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Rep: Reputation: 83
Question SSH: running various commands on a router


Hi!

I have set up ssh to connect with a RSA key to a router. Now, I want to be able to run a chain of commands on that router the problem is that I can't send them separated with ; cause the router doesn't understand the separation, so I have to send the "<enter>" keys somehow.

I tried to do it like this:

( echo ping localhost; echo ping localhost; ) | ssh -i blah user@router

The connection is established, but it gets broken after login and no command is executed.

Is there a way I could tell ssh to read a text file where the chain of commands is?

Thanks in advance
 
Old 06-18-2009, 04:10 PM   #2
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
What about trying the "\n" character sequence i.e.

Code:
ssh -i blah user@router "Command1\n Command2\n"
 
Old 06-18-2009, 04:21 PM   #3
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Try:
Code:
ssh -i blah user@router "command1; command2"
 
Old 06-19-2009, 07:34 AM   #4
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Original Poster
Rep: Reputation: 83
the \n trick, I would expect it to work, however the problem is a little more complicated, as the commands are in a text file. What I finally did was this:

ssh user@host "`cat file_with_commands`"

And it works.
 
  


Reply

Tags
commands, ssh


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Log all SSH commands at ssh-client. mohammednv Linux - Networking 6 01-26-2008 05:02 AM
giving a router commands fakie_flip Linux - Software 1 08-01-2006 10:56 PM
ssh running remote commands Nikee Linux - Security 5 02-04-2006 03:00 AM
Running commands over ssh iago Programming 8 11-28-2004 12:13 PM
running commands automatically via SSH tpfraz Linux - General 1 02-13-2004 09:12 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration