Using Perl NET::TELNET module
I am just starting to look at the NET:TELNET module available in perl. I am new to both linux and perl. I have managed to get the modules installed but am having problems getting the output back from commands that i issue. My script file is :
#!/usr/bin/perl use Net::Telnet; $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die' Prompt=>'/\$ $/i'); $telnet->open('192.168.1.4'); $telnet->login('danny', 'danny'); print $telnet->cmd('ls'); When testing this on my local suse box i get the error : linux:/home/test-stuff # ./test.pl syntax error at ./test.pl line 8, near "Prompt" Execution of ./test.pl aborted due to compilation errors. linux:/home/test-stuff # What am i doing wrong ? Ultimatley my aim is to use NET::TELNET::CISCO module to automate commands to cisco routers. I though id better get the above working first as im new to it ! Any help appreciated Thanks |
Should read:
Code:
$telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt=>'/\$ $/i'); |
Thanks, it now seems to let me login however the 'ls' command is not being run. The output i am seeing is :
linux:/home/test-stuff # ./test.pl eof read waiting for login prompt: Welcome to SuSE Linux 9.2 (i586) - Kernel 2.6.8-24.11-default (3). at ./test.pl line 6 linux:/home/test-stuff # my current script is : #!/usr/bin/perl use Net::Telnet; $telnet = new Net::Telnet ( Timeout=>20, Errmode=>'die', Prompt=>'/\$ $/i'); $telnet->open('192.168.1.3'); $telnet->login('root', 'password'); print $telnet->cmd('ls'); Any suggestions ? Thanks |
Try adding some error checking. Something like:
Code:
$telnet->login('root', 'password') or die("Problem logging in: $!"); |
Full path to ls may help. Probably /bin/ls.
|
All times are GMT -5. The time now is 11:40 AM. |