Перезагрузка с помощью SNMP\\
OID .1.3.6.1.4.1.11863.6.3.1.1.0\\
Принимаемые значения\\
INTEGER {notReBoot(0), reboot(1), reBootAndSave(2) }\\
Скрипт аналогичен команде\\
''snmpset -c [community] -v[version] [host] .1.3.6.1.4.1.11863.6.3.1.1.0 i 1''
#!/usr/local/bin/perl
use strict;
use warnings;
my $community = defined($ARGV[0]) ? shift(@ARGV) : die "use: [community] [version] [host] [reboot | savereboot]\n";
my $version = defined($ARGV[0]) ? shift(@ARGV) : die "use: $community [version(read-write)] [host] [reboot | savereboot]\n";
my $host = defined($ARGV[0]) ? shift(@ARGV) : die "use: $community $version [host] [reboot | savereboot]\n";
my $state = defined($ARGV[0]) and ($ARGV[0] eq 'reboot' or $ARGV[0] eq 'savereboot') ? shift(@ARGV) : die "use: $community $version $host [reboot | savereboot]\n";
use Net::SNMP;
use constant SNMP_OID_REBOOT => '.1.3.6.1.4.1.11863.6.3.1.1.0';
my $snmp = Net::SNMP->session(
-hostname => $host,
-community => $community,
-version => $version
);
defined($snmp) or die $snmp->error() . "\n";
my $result = $snmp->set_request(
-varbindlist => [SNMP_OID_REBOOT, INTEGER, $state eq 'reboot' ? 1 : 2]#.INTEGER {notReBoot(0), reboot(1),reBootAndSave(2) }
);
defined($result) or die $snmp->error() . "\n";
print "Reboot...\n";
#!/usr/local/bin/perl
use strict;
use warnings;
use constant HOST => '';
use Net::SNMP;
use constant SNMP_COMMUNITY => 'private';#read-write
use constant SNMP_VERSION => '2c';
use constant SNMP_OID_REBOOT => '.1.3.6.1.4.1.11863.6.3.1.1.0';
my $snmp = Net::SNMP->session(
-hostname => HOST,
-community => SNMP_COMMUNITY,
-version => SNMP_VERSION
);
defined($snmp) or die $snmp->error() . "\n";
my $result = $snmp->set_request(
-varbindlist => [SNMP_OID_REBOOT, INTEGER, 1]#.INTEGER {notReBoot(0), reboot(1),reBootAndSave(2) }
);
defined($result) or die $snmp->error() . "\n";
print "Reboot...\n";
#!/usr/local/bin/perl
use strict;
use warnings;
use constant HOST => '';
use Net::Telnet;
use constant TELNET_LOGIN => '';
use constant TELNET_PASSW => '';
use constant TELNET_LOGS => 'telnet.log';
use constant SAVE_CONFIG => 'N';#Saving current user config? Y or N
my $telnet = new Net::Telnet(
Timeout => 3,
Errmode => "return",
Output_log => TELNET_LOGS,
Input_log => TELNET_LOGS
);
$telnet->open(Host => HOST);
$telnet->waitfor('/User:/m') ? $telnet->print(TELNET_LOGIN) : ($telnet->close() and die $telnet->errmsg() . "\n");
$telnet->waitfor('/Password:/m') ? $telnet->print(TELNET_PASSW) : ($telnet->close() and die $telnet->errmsg() . "\n");
$telnet->waitfor('/>/m') ? $telnet->print('en') : ($telnet->close() and die $telnet->errmsg() . "\n");
$telnet->waitfor('/#/m') ? $telnet->print('ena') : ($telnet->close() and die $telnet->errmsg() . "\n");
$telnet->waitfor('/Password:/m') ? $telnet->print(TELNET_PASSW) : ($telnet->close() and die $telnet->errmsg() . "\n");
$telnet->waitfor('/#/m') ? $telnet->print('reboot') : ($telnet->close() and die $telnet->errmsg() . "\n");
$telnet->waitfor('/ Saving current user config before reboot\? \(Y\/N\):/m') ? $telnet->print(SAVE_CONFIG) : ($telnet->close() and die $telnet->errmsg() . "\n");
$telnet->waitfor('/ This will reboot (all )?device(s)?\. Continue\? \(Y\/N\):/m') ? $telnet->print('Y') : ($telnet->close() and die $telnet->errmsg() . "\n");
$telnet->close();
print "Reboot...\n";
В данном случае строка с последним вопросом у нас отличается\\
#V2.20 This will reboot all devices. Continue? (Y/N):\\
#V4 This will reboot device. Continue? (Y/N):\\
Поэтому мы берем в скобки слова 'all ' и букву 's' в конце слова devices и используем квантификатор **?**\\
что делает необязательным наличие этих последовательностей символов для выполнения условия\\
$telnet->waitfor('/ This will reboot (all )?device(s)?\. Continue\? \(Y\/N\):/m')