[TriLUG] scripted sesssions with ssh

Shawn Hartsock hartsock at acm.org
Mon Jul 6 11:37:14 EDT 2009

Would something like this work for you?

use Net::SSH::Perl ;

$scon = Net::SSH::Perl->new ("www.savethetrain.org.uk");
# for the record, I don't like this bit... and would prefer auth keys
print "looking around ...\n";
($output,$errors,$exit) = $scon->cmd("ls -l");
print $output;

Naturally, you can do the same sorts of things in Python, Java, C or
any language you prefer.
For example in Python:

Of course, I'm almost afraid to suggest it since it sounds like its
almost time for your team to consider something like Nagios.

On Mon, Jul 6, 2009 at 11:07 AM, Joseph Mack NA3T<jmack at wm7d.net> wrote:
> At $work I nonitor about 1000 parameters every 5 minutes (cpu usage,
> ethernet throughput, temperature of disks...). I'm required to do this by
> ssh from another machine. This involves scripts which make calls like
> monitoring_machine#: result=`ssh remote_machine du | grep ...`
> This works, except the large number (1000/5mins) of ssh calls cause a high
> load on the both the client and remote machine.
> My $manager says that since he can ssh to the remote machine and do the at
> the command prompt the same thing as my scripts do, that my scripts should
> only have to make one ssh connection and they should run all their commands
> and receive the responses without exiting the ssh session.
> The only way I can see to do this is with expect scripts (it would be a
> nightmare to code up)
> Are there other ways for a script to open an ssh connection, make about 1000
> calls, and process 1000 respones before closing the ssh session?
> My preference would be to run the monitoring on each machine and ship the
> results back to the monitoring machine, but I'm not allowed to do that (it
> would result in too much load on the monitored machine).
> Thanks
> Joe
> --
> Joseph Mack NA3T EME(B,D), FM05lw North Carolina
> jmack (at) wm7d (dot) net - azimuthal equidistant map
> generator at http://www.wm7d.net/azproj.shtml
> Homepage http://www.austintek.com/ It's GNU/Linux!
> --
> TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
> TriLUG FAQ  : http://www.trilug.org/wiki/Frequently_Asked_Questions

/** Shawn.Hartsock http://hartsock.blogspot.com */

More information about the TriLUG mailing list