As I already told you in the chatterbox, the safest and sanest way is to set up passwordless keys on the target machines and then to simply use ssh to do your bidding:
my $command = 'cat /etc/passwd';
for my $machine (@machines) {
my @output = `ssh '$machine' $command`;
...
}
If ssh is out of the game, consider using rsh instead - it's mostly like ssh (if I remember correctly).
If that's also not an option, consider Net::Telnet or simply use IO::Socket to connect to port 23 and pretend to be a dumb terminal. | [reply] [d/l] [select] |
Sorry Corion ... not used to the chatterbox yet.
I cannot use ssh or rsh, as this is a straight telnet session to a closed source system.
I understand that I can use Net::Telnet or IO:Socket. It is the 'text capture' part that has me stumped (very new to perl - sorry).
I only need to start the capture when I issue the command to start the report, then turn it off and write to the file, after the report is complete.
Will either of the two mods you mentioned above also handle this capture or is there something else I will need?
Thank you.
| [reply] |
use Net::Telnet ();
$t = new Net::Telnet (Timeout => 10,
Prompt => '/bash\$ $/');
$t->open("sparky");
$t->login($username, $passwd);
@lines = $t->cmd("who");
print @lines;
I interpret this code as
- logging on to a machine "sparky", with a username of $username and a corresponding password
- executing a command, who, and capturing its output in @output
- printing the captured output
I'm not sure where the synopsis of Net::Telnet diverges from your stated requirements, or where you've found flaws in the operation of Net::Telnet for your required operation, so I can't help you much further. If you have problems with writing the lines captured in @output to a file, consider looking at open and print, but neither of these have anything to do with a telnet connection. | [reply] [d/l] [select] |