cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2773
Views
5
Helpful
6
Replies

TCL Script to change hostnames from upper case letters to lower case

packettracer86
Level 1
Level 1

Hey guys,

could someone provide me (not sure if it`s even possible with tcl) a script which changes the hostname of a device from upper case to lower case letters?

The hostname always consits of 5 letters and 3 numbers. e.g ABCDE012

And the script should change it to abcde012.

My goal is to roll it out with a NMS on about ~100 switches.

 

Thank you in advance!

1 Accepted Solution

Accepted Solutions

Joe Clarke
Cisco Employee
Cisco Employee

The Tcl code to do this is rather simple:

 

set hostname [string tolower $hostname]

 

Then, if it's tclsh you're using:

 

ios_config "hostname $hostname"

View solution in original post

6 Replies 6

Joe Clarke
Cisco Employee
Cisco Employee

The Tcl code to do this is rather simple:

 

set hostname [string tolower $hostname]

 

Then, if it's tclsh you're using:

 

ios_config "hostname $hostname"

Hi Joseph,

thank you for the quick response!

Do i have to run this as a event manager applet or how can i execute it?

 

 

My Environment:

Hardware: WS-C2960CG-8TC-L

Software: C2960c405ex-UNIVERSALK9-M 15.2(2)E

 

 

This is tclsh code.  Just execute tclsh and paste the code in.

Why does it not work? :/

 

SWITCHNAME#tclsh

SWITCHNAME(tcl)#set hostname [string tolower $hostname]
can't read "hostname": no such variable

SWITCHNAME(tcl)#ios_config "hostname $hostname"
can't read "hostname": no such variable

SWITCHNAME(tcl)#tclquit
SWITCHNAME#

 

 

I had assumed you already had extracted the hostname into the $hostname variable.  But to do that, use:

 

set hostname [info hostname]

Hi Joseph,

okay that makes absolutly sense.

Thank you for the support, it works like a charm!