Interesting idea...might be something I dabble with in my spare time (since I have so much of it ;-), uh...)...

ktb wrote:
I'm trying to write a perl wrapper to manage all my ssh sessions. My
idea is to put the following code into a while loop. The problem I'm
having is I would like to be able to log into a remote server and then
hit, say ^sn which would suspend the current ssh session and activate
the wrapper. You could then log into a different server. Then you could hit ^ls to get a list of sessions to select the session you want and bring it to the foreground. This is probably way beyond my capability at this time but any pointers would be appreciated.
Thanks,
kent

#!/usr/bin/perl
use strict;
use warnings;
my $user_name = 'user_name';
my $ssh = '/usr/bin/ssh';
my @server_ip = qw (
137.44.55.3
137.44.55.210
137.44.55.41
);

my %servers = (
0 => "abaddon",
1 => "apocalypse",
2 => "buffy",
q => "quit"
);

for (keys %servers) {
print "$_ $servers{$_}\n";
}
print "Chose number: ";
chomp(my $num = <STDIN>);
unless ($num eq 'q') {
system("$ssh $user_name\@$server_ip[$num]");
} else {
exit;
}

Because of how 'system' works it essentially forks and execs, at which point you lose all control over passing it data, which means you can't send it further commands or use it as an interactive shell. Theoretically you might be able to use a pipe or some such over an Open2 call though I can't think of how off the top of my head.

As an alternate solution you might consider using the Net::SSH::Perl which provides a wrapper to sending commands over an ssh channel, then rather than sending the command directly to the ssh session and switching session, instead you could create your own "shell" that you would interact with, but on the backside it would simply pass the command through to the ssh connection established. This would require setting up a "pool" of ssh connections that you could make the setting of which part of your interactive "shell"... at any given point your shell would know which connection within the pool to send the command to. I am looking at doing something like this for watching a series of directories on a remote machine in an application I am developing, but haven't played with it as yet....

If you are determined to use the command line ssh there may be a way to do this with POE (sorry have it on the brain right now) but again this would be a pretty major undertaking for a novice (don't know your background).

On the other hand, this whole idea should be able to be handled using shell job control and simply suspending the ssh process and then recovering (foregrounding) whichever one you need at a given point, but what fun would that be?

http://danconia.org


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to