cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 7

Script to remove characters out of host name

Jump to solution

I have about 100 ASAs we need to change the host name on. When they were first created someone added ASA[City] as the host name. I tried to make a script to delete the first 3 characters (the ASA part) but it keeps giving me strange results.

Here is what I tried:

conf t

${SysName}${CTRL+A}${RIGHTARROW}${RIGHTARROW}${RIGHTARROW}${BACKSPACE}${BACKSPACE}${BACKSPACE}hostname ${CRLF}

I basically tried to simulate typing the host name, going to the beginning of the command line(CTRL+A), arrowing over and back spacing the first 3 letters, then adding "hostname " since the cursor should be at the beginning of the line again.

When I try and run this, it basically doesn't understand most of my variables even though they are in the manual. (backspace wasn't, but I had to try)

here is the output:

4/19/2018 2:23:35 PM on ASANewYork (X.X.X.X) by Admin

conf t

ASANewYork${CTRL+A}${RIGHTARROW}${RIGHTARROW}${RIGHTARROW}${BACKSPACE}${BACKSPACE}${BACKSPACE}hostname

Is there an easy way to accomplish what I'm trying to do?

Thanks,

Travis

Tags (2)
0 Kudos
1 Solution

treiling​ Here is a link showing how to call the custom property as a variable when running the NCM script.

Re: Clearing Interface Counters

Your NCM script would look something like this:

configure terminal  
hostname ${NodeTempName} 
end
copy run start

Please let us know if you still need assistance.

Thank you,

-Will

View solution in original post

4 Replies
Level 7

Thank you very much wluther​!

That worked out pretty good.

I created a new custom property, exported my node info to excel, used "text to columns" to get rid of the ASA in the front of the host name, imported that change to fill in the new custom property and then used your script in a job to apply the change. Not one single error! Saved me a lot of time and frustration for sure. I really appreciate your help on this, and I can use this method to make other bulk changes down the road.

Excellent news, treiling​. I'm glad everything worked out well for you. If you need anything else, Thwack is here to help.

Thank you,

-Will

0 Kudos

treiling​ I would recommend using the SDK to accomplish this, or at the very least, the Custom Property Editor.

Create a new custom property (ex. NodeTempName), then use the SDK to build your new name and store it as that new property. Alternatively, if you don't wish to use the SDK, you can use the custom property editor/manage custom properties to create new names in that new "NodeTempName" custom property. Then, once you have the actual names you want to use, stored within a CP on each node, you can call that CP within an NCM script.

treiling​ Here is a link showing how to call the custom property as a variable when running the NCM script.

Re: Clearing Interface Counters

Your NCM script would look something like this:

configure terminal  
hostname ${NodeTempName} 
end
copy run start

Please let us know if you still need assistance.

Thank you,

-Will

View solution in original post