In network administration, automation is key to efficiency and consistency. Cisco devices support TCL (Tool Command Language) scripting, which allows network administrators to automate various tasks. In this post, we’ll explore how to create and run scripts on Cisco devices for common administrative tasks.
Why Use Scripts on Cisco Devices? Link to heading
Scripting on Cisco devices offers several benefits:
- Automation: Reduce manual configuration time
- Consistency: Ensure uniform configurations across devices
- Error Reduction: Minimize human errors in repetitive tasks
- Time-Saving: Execute complex commands with a single script
- Documentation: Scripts serve as documentation of configuration changes
Prerequisites Link to heading
Before creating scripts, ensure:
- Your Cisco device supports TCL scripting
- You have sufficient flash memory
- You have the necessary permissions (privilege level 15)
- The device is in enable mode
Creating an Initial Configuration Script Link to heading
This script creates a base configuration file that can be used to standardize switch configurations:
Switch#
# Create the script
tclsh
puts [ open "flash:BASE.CFG" w+ ] {
hostname DLS1
ip domain-name CCNP.NET
no ip domain lookup
interface range f0/1-24 , g0/1-2
shutdown
exit
vtp mode transparent
line con 0
no exec-timeout
logging synchronous
exit
end
}
tclquit
# Load the initial BASE.CFG file to running-config
copy BASE.CFG running-config
Creating a Switch Reset Script Link to heading
This script automates the process of clearing and reloading a switch:
Switch#
# Create the script
tclsh
puts [ open "flash:RESET.TCL" w+ ] {
wr
typeahead "\n"
erase startup-config
delete /force flash:vlan.dat
typeahead "\n"
delete /force flash:multiple-fs
typeahead "\n"
puts "Reloading the switch in 1 minute, type 'reload cancel' to abort"
typeahead "\n"
reload in 1 RESET.TCL SCRIPT RUN
}
tclquit
# Run the script
tclsh RESET.TCL
Creating a Router Reset Script Link to heading
Similar to the switch script, but adapted for router-specific needs:
Router#
# Create the script
tclsh
puts [ open "flash:RESET.TCL" w+ ] {
wr
typeahead "\n"
erase startup-config
typeahead "\n"
puts "Reloading the router in 1 minute, type 'reload cancel' to abort"
typeahead "\n"
reload in 1 reason RESET.TCL SCRIPT RUN
}
tclquit
# Run the script
tclsh RESET.TCL
Scripting on Cisco devices using TCL can significantly improve network administration efficiency. The examples provided here cover basic but essential tasks.