Hi everyone.
I am trying to retrieve some information from a text file, but am not sure if the format is ok. Could someone please tell me how its supposed to be? Currently its like this
Host:
172.24.100.111
Dialer:
1
Eventually this data file will have multiple hosts, with dialers linked to its respective host. I have the script below.
Thanks for your help
Kind regards
Sam
#!E:\Perl\bin
use strict;
use warnings;
use Net::Telnet::Cisco;
use Getopt::Long;
# Globals. Change these!
our $LOGIN = 'LOGIN';
our $PASS = 'password';
our $ENPASS = 'password';
# Parse command-line options
my ($host, $dialer);
GetOptions( "host=s" => \$host, "dialer=s" => \$dialer );
unless ( defined $host && defined $dialer ) {
warn "You forgot to pass me some arguments!\n";
print usage();
exit 1;
}
# Read from logfile
open LOGFILE, "> log.txt" or die "Can't read from log.txt: $!";
my $title = <LOGFILE>;
print "Report Title: $title", <LOGFILE>;
close LOGFILE or warn $!;
# Router automation
my $session = Net::Telnet::Cisco->new( Host => $host );
$session->login( $LOGIN, $PASS );
if ( $session->enable( $ENPASS ) ) {
print "My privileges: " . $session->cmd( 'show privilege' );
$session->cmd( 'configure terminal' );
$session->cmd( "interface Dialer $dialer" );
$session->cmd( 'No Shutdown' );
} else {
warn "Can't enable: " . $session->errmsg;
}
exit;
sub usage { "$0 --host=hostname --dialer=number" }
__END__
I am trying to retrieve some information from a text file, but am not sure if the format is ok. Could someone please tell me how its supposed to be? Currently its like this
Host:
172.24.100.111
Dialer:
1
Eventually this data file will have multiple hosts, with dialers linked to its respective host. I have the script below.
Thanks for your help
Kind regards
Sam
#!E:\Perl\bin
use strict;
use warnings;
use Net::Telnet::Cisco;
use Getopt::Long;
# Globals. Change these!
our $LOGIN = 'LOGIN';
our $PASS = 'password';
our $ENPASS = 'password';
# Parse command-line options
my ($host, $dialer);
GetOptions( "host=s" => \$host, "dialer=s" => \$dialer );
unless ( defined $host && defined $dialer ) {
warn "You forgot to pass me some arguments!\n";
print usage();
exit 1;
}
# Read from logfile
open LOGFILE, "> log.txt" or die "Can't read from log.txt: $!";
my $title = <LOGFILE>;
print "Report Title: $title", <LOGFILE>;
close LOGFILE or warn $!;
# Router automation
my $session = Net::Telnet::Cisco->new( Host => $host );
$session->login( $LOGIN, $PASS );
if ( $session->enable( $ENPASS ) ) {
print "My privileges: " . $session->cmd( 'show privilege' );
$session->cmd( 'configure terminal' );
$session->cmd( "interface Dialer $dialer" );
$session->cmd( 'No Shutdown' );
} else {
warn "Can't enable: " . $session->errmsg;
}
exit;
sub usage { "$0 --host=hostname --dialer=number" }
__END__