[plug] multiple commands in a single ssh connection

Adam Hewitt ahewitt at theozhewitts.com
Fri Oct 10 12:34:52 WST 2008


Thanks Andrew, Gregory and Daniel,

I have tried most of what has been suggested already which leads me to
believe that its something to do with the remote host....which I
should have specified as being Cisco switches.

Basically I have a bunch of large modifications to do to the network I
am working on which require a lot of planning (read: auditing) and I
don't want to be chasing down mac addresses and such one at a time
automatically. I also want to be able to push config changes to the
switches in bulk which requires a series of commands in a single ssh
session.

Adam.

On Fri, Oct 10, 2008 at 12:27 PM, Daniel Pittman <daniel at rimspace.net> wrote:
> "Adam Hewitt" <ahewitt at theozhewitts.com> writes:
>
>> I have a requirement to write a script that is able to send multiple
>> lines of commands via a single ssh connection. I have tried a whole
>> bunch of things but nothing seems to be working and google isn't being
>> friendly.
>>
>> Is this actually possible and if so can someone give me a pointer?
>
> As pointed out elsewhere, ';' is your friend, as is writing a shell
> script that can be run as a single command on the remote host.
>
> You could just try sending the command with newlines embedded as the
> single argument to ssh; this works fine for me:
>
>    ssh example.com 'echo one
>    echo two'
>
> That runs as two commands.
>
>
> You might, perhaps, find that Expect or the port of it to your preferred
> scripting language, useful for driving the interactive ssh command and
> responding to the remote commands.
>
> Alternately, you will find that there are SSH libraries available for
> most common languages, which will allow you to establish the connection
> and send commands in series.
>
>
> Finally, you could approach this by outlining what you are trying to
> do -- the problem you face, not the issue with the solution you think
> you have found.
>
> In my experience "I need to send multiple commands through a single SSH
> session" is usually a mistake in my probably analysis -- every time I
> have thought that there has been a better way...
>
> So, if you tell us what the problem is we can, perhaps, suggest a more
> effective solution for you.
>
> Regards,
>        Daniel
> _______________________________________________
> PLUG discussion list: plug at plug.org.au
> http://www.plug.org.au/mailman/listinfo/plug
> Committee e-mail: committee at plug.linux.org.au
>



More information about the plug mailing list