Bulk Device Maintenance Mode Script

Garrett Caudle

Out of necessity, I needed a quick easy way to put 1 or many devices in maintenance mode at once, and ran across a scheduling maintenance mode script on here that I have modified to instead use.... -"ON/OFF" variable you change depending on the desired mode -DEVICES where you enter a list of devices by name or regex such as hostname prefix

So if you want them in maintenance mode, chance the mode to "ON", drive your DEVICES, SAVE the script then Run it. Done.

Hope it helps someone else like it has me.

sub custom_toggle_maint_mode {
# Script to toggle maintenance mode on one or maybe devices instantly!
# Use below variable to set maintenance mode "ON" or "OFF" for devices

my $toggle_maint_mode = "OFF";
my $type = "device";
my $group = "maintenance_mode";

# put your devices here using regex like the devices hostname prefix or specific hostnames or both
my @devices = ( "/^bldg1-/", "My-Core-Sw1", );

group_manual_load_cfg ();

if ($toggle_maint_mode eq "ON") {
# Assign

for my $device (@devices) {
errlog ($ERR_INFO, "Putting %s into maintenance mode", $device);
group_manual_assign ($type, $device, $group);
}
}
elsif ($toggle_maint_mode eq "OFF") {
# Clear
for my $device (@devices) {
errlog ($ERR_INFO, "Taking %s out of maintenance mode", $device);
group_manual_clear ($type, $device, $group);
}
}

group_manual_save_cfg ();
adb_flush ();

}

Comments

0 comments

Please sign in to leave a comment.