How can I run a command on a remote machine with Perl?
- by Bharath Kumar
I'm using following code to connect to a remote machine and try to execute one simple command on remote machine.
cat tt.pl
#!/usr/bin/perl
#use strict;
use warnings;
use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>2, Errmode=>'die');
$telnet->open('172.168.12.58');
$telnet->waitfor('/login:\s*/');
$telnet->print('admin');
$telnet->waitfor('/password:\s*/');
$telnet->print('Blue');
#$telnet->cmd('ver > C:\\log.txt');
$telnet->cmd('mkdir gy');
You have new mail in /var/spool/mail/root
[root@localhost]#
But when I'm executing this script it is throwing error messages
[root@localhost]# perl tt.pl
command timed-out at tt.pl line 12
[root@localhost]#
Please help me in this