Showing posts with label Expect. Show all posts
Showing posts with label Expect. Show all posts

Monday, December 28, 2009

Script to turn off PoE power using Energywise

My environment: Cisco 3560E

Besides shutting down the switchport, you can turn off the PoE power via the Energywise command.  Before you run this script, setup your energywise domain with the command “energywise domain panda security shared-secret eatsbamboo”

#!/usr/bin/expect

set timeout 5
log_user 1
set hostlist "pandasw01"
set prompt "pandasw01"
foreach host $hostlist {
#set prompt [append $host "#"]
set promptcfg [append $prompt "(config)#"]
spawn telnet $host
expect $prompt
send "conf t\r"
expect $promptcfg
send "int range fa0/1 - 23\r"
expect $promptcfg
send "energywise level 0\r"
expect $promptcfg
send "end\r"
expect $prompt
send "exit\r"
}

Script to Turn off Cisco Autonomous Access Point radio interface

My environment: Cisco 861W

You can turn off the radio interface of the autonomous AP when you don’t use it to save power.

#!/usr/bin/expect

set timeout 5
log_user 1
set hostlist "pandaap01"
foreach host $hostlist {
set prompt [append $host "#"]
set promptcfg [append $prompt "(config)#"]
spawn telnet $host
expect $prompt
send "conf t\r"
expect $promptcfg
send "int dot11radio0\r"
expect $promptcfg
send "shut\r"
expect $promptcfg
send "end\r"
}

Friday, December 18, 2009

Script to backup Cisco Device Config

A handy expect script on Linux to backup your routers, switches, AP, or other IOS devices configuration.  Make sure you have “expect” installed on your Linux box.

#!/usr/bin/expect

set timeout 5
log_user 1

# Include your hosts in the hostlist
set hostlist "rt01 rt02 sw01 sw02"
foreach host $hostlist {
set prompt [append $host "#"]
spawn telnet $host
expect $prompt
send "term len 0\r"
expect $prompt
set time [exec date \+\%y\%m\%dT\%H\%MJ]
set filename [append host "-" $time]

# The config file storage location
log_file /home/pandaeatsbamboo/cfgbackup/$filename
send "show run\r"
expect $prompt
send "exit\r"
log_file
}