Master TCL Scripts on Cisco IOS – Automate Tasks & Boost Productivity Like a Pro!

 


Introduction

As network engineers, we often repeat the same CLI commands every day. TCL scripting inside Cisco IOS empowers us to automate tasks like ping testing, configuration backup, and data collection directly from the router — without external tools. In this article, I’ll show you how TCL works, why you should use it, and how to run your first automation script.


What is TCL in Cisco IOS?

TCL (Tool Command Language) is a built-in scripting interpreter inside many Cisco IOS versions. It allows you to write mini-programs to automate testing and operation tasks without leaving the router CLI.


Basic Commands to Start TCL

Command Description
tclsh Start the TCL shell in IOS
tclquit Exit the TCL interpreter
puts Print a message on screen
foreach Loop through a list of items
eval Force TCL to run a CLI command string

Example 1 – Automate Ping Tests Using TCL

tclsh
foreach ip {8.8.8.8 1.1.1.1 9.9.9.9} {
  set cmd "ping $ip"
  puts "Running: $cmd"
  eval $cmd
}
tclquit

✅ What this script does:

  • Enters the TCL shell.

  • Loops through a predefined list of IP addresses.

  • Builds a normal “ping” command for each IP.

  • Executes it just as if you were typing manually.

  • Perfect for troubleshooting and quick testing.


Why Use TCL Scripting?

  • 🚀 Saves time on repetitive CLI commands

  • 🔄 Automates testing (connectivity, routing, QoS checks)

  • 📦 Collects information across multiple interfaces

  • 🔐 Runs locally inside the router (doesn’t need external access)


Example 2 – Backup Running Configuration via TCL

tclsh
set t [clock format [clock seconds] -format "%Y%m%d-%H%M"]
set fh [open "flash:backup_$t.cfg" w]
puts $fh [eval "show running-config"]
close $fh
tclquit

✅ This script generates a timestamped backup of your running-config and stores it in router flash:


Conclusion

TCL scripting is a powerful native automation capability hiding inside Cisco IOS. Whether you're studying for CCNA/CCNP or managing large enterprise routers, mastering TCL can improve your efficiency and make your daily tasks easier. In future posts, I’ll show how to trigger these scripts automatically using EEM (Embedded Event Manager).




Comments