I'm new to Perl. And I have used following code from one forum to connect to one of the server. but throwing error messages
[root@Cus]# cat tt.pl
#!/usr/bin/perl
use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>2, Errmode=>'die');
$telnet->open('10.0.0.28');
$telnet->waitfor('/login:/');
$telnet->print('administrator');
$telnet->waitfor('/Password:/');
$telnet->print('test');
$telnet->waitfor('/switch8-12>/');
$telnet->print('whoamI');
$output=$telnet->waitfor('/switch8-12>/');
print $output;
But throwing following error messages.
[root@Cus]# ./tt.pl
./tt.pl: line 3: use: command not found
./tt.pl: line 4: syntax error near unexpected token `('
./tt.pl: line 4: `$telnet = new Net::Telnet ( Timeout=>2, Errmode=>'die');'
1. Run the "perl" command with the Perl script included in the command line. For example, enter the following command line in a shell window: /home/herong$ perl -e "print 'Hello world!
"Perl" officially stands for "Practical Extraction and Report Language." It was originally a language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information. It quickly became a good language for many system management tasks.
Your answer Open your Python code in your Python editor of choice. Go to the line in the code where you want to run your Perl script. Type "pyth. RunPerl.
My guess is that you're using a weird flavour of unix that doesn't respect the #!
line, and is trying to run the script via the shell instead of via perl.
Another reason why this might happen is if tt.pl
starts with a blank line. The #!
must appear at the very start of the file.
Try running perl tt.pl
and see what happens.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With