[plug] multiple commands in a single ssh connection

W.Kenworthy billk at iinet.net.au
Fri Oct 10 12:58:58 WST 2008


Perl has some modules for controlling IOS - I know there is a telnet
one, may be an ssh one as well (or tunnel telnet through ssh?)

Billk

On Fri, 2008-10-10 at 12:34 +0800, Adam Hewitt wrote:
> 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
> >
> _______________________________________________
> 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