cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
13846
Views
25
Helpful
9
Replies

Comments in CLI script

gretchen1983
Level 1
Level 1

Is there some word or character in CUCM CLI that signifies a comment? 

I want this every few months when I'm doing CLI work.

 

I've guessed at several and none work. 

I googled and didn't find anything.

I emailed a UC engineer who said 'no such thing'. 

That can't be true, can it?

 

  • !---CLI comment, nope
  • #--- what is the CLI comment signifier? nope
  • >> script for for identifying nodes<<
  • @--this script identifies the node
  • show myself
  • show network eth0
  • show date

 

Yeah, I know I can just enter something that I know is not a command like:

  • == put your comment here

and get the 'invalid command' error, but I don't want the clutter in the log files.

1 Accepted Solution

Accepted Solutions

The question was not a stupid by any means, I apologize if my reply came across as abrasive, that was not my intent. I do a decent amount of work with Cisco UC products and have never had a need to insert comments directly into the CLI, I responded honestly.

 

If you do a lot of repetitive CLI work on multiple hosts, I would recommend using something like an expect shell script. You can insert comments into your shell script without needing to "send" them as commands in the UCOS CLI session. Here is an example which shows how you can build an expect script to interact with the CUCM CLI and comment freely within the script (in this case # is used since it is a shell script):

 

#!/usr/bin/expect -f
set timeout 120
set username [lindex $argv 0]
set password [lindex $argv 1]
set hostname [lindex $argv 2]


# Begin expect block
spawn ssh $username@$hostname

# The following statement will automatically accept the SSH connection warning if presented
expect {
	"Are you sure you want to continue connecting (yes/no)?" {
		send "yes\r" # Test midline comment
		exp_continue
	}
# The following statement will enter the password for the specified user account
	"administrator@$hostname's password:" {
		send "$password\r"
		expect "admin:"
# The following will dump the risdb phone data for the current UCM node and then drop the shell into
# interactive mode
		send "\r\r\rshow risdb query phone\r"
		interact
	}
}

exit

 

Everyone in this community who responds to threads does so on their own personal time in an effort to help others get answers to their questions. I think you would be hard pressed to find someone who genuinely had a negative intent in trying to provide a solution.

 

I hope this helps!

 

- Jon

View solution in original post

9 Replies 9

Jonathan Unger
Level 7
Level 7

The CLI that you are presented with when you SSH to a UC box is a java based command interpreter. I do not think that it has any provision to make a comment, I also can't really think of a good reason to have a "comment" ability within the CLI. Sorry, I know this is not the answer you were looking for, but pretty sure this is not possible.

>> I also can't really think of a good reason to have a "comment" ability within the CLI

 

I just gave you a good reason.  Have you never done repetitive work on multiple nodes?

 

And any CLI should have a provision for comments.

 

 

 

The question was not a stupid by any means, I apologize if my reply came across as abrasive, that was not my intent. I do a decent amount of work with Cisco UC products and have never had a need to insert comments directly into the CLI, I responded honestly.

 

If you do a lot of repetitive CLI work on multiple hosts, I would recommend using something like an expect shell script. You can insert comments into your shell script without needing to "send" them as commands in the UCOS CLI session. Here is an example which shows how you can build an expect script to interact with the CUCM CLI and comment freely within the script (in this case # is used since it is a shell script):

 

#!/usr/bin/expect -f
set timeout 120
set username [lindex $argv 0]
set password [lindex $argv 1]
set hostname [lindex $argv 2]


# Begin expect block
spawn ssh $username@$hostname

# The following statement will automatically accept the SSH connection warning if presented
expect {
	"Are you sure you want to continue connecting (yes/no)?" {
		send "yes\r" # Test midline comment
		exp_continue
	}
# The following statement will enter the password for the specified user account
	"administrator@$hostname's password:" {
		send "$password\r"
		expect "admin:"
# The following will dump the risdb phone data for the current UCM node and then drop the shell into
# interactive mode
		send "\r\r\rshow risdb query phone\r"
		interact
	}
}

exit

 

Everyone in this community who responds to threads does so on their own personal time in an effort to help others get answers to their questions. I think you would be hard pressed to find someone who genuinely had a negative intent in trying to provide a solution.

 

I hope this helps!

 

- Jon

Ah, Expect!  Yes.  That was the first thing I thought of, but I don't have a Linux box that can reach these nodes.  I'm stuck with Windows. 

 

I looked into Powershell, and there was an Await plug-in that was designed to mimic Expect, but it's apparently deprecated (or I couldn't figure out how to load it.) 

 

Then I tried it with 'plink' but really needed the 'expect ' functionalities. I was wrestling with delays and gave up.

 

Then I discovered SecureCRT (SCRT) running VBScript has "send" and "wait for string' (similar to Expect functionality) which works well enough.  So I run all the commands and collect the results in the SCRT log. 

 

However looking at the log of 100 machines, I don't know which accounting group I'm looking at, so I added "== primary accounting group xxxxxxxxx" to the commands, and now, when I look through the logs I can tell which machine and group I'm looking at.  It makes analysis a lot easier. 

 

So this works, except I get the error message below every entry.  If I could flag it as a comment it shorten my log by a few hundred lines and make it easier to read as well.

 

Thanks for your reply. 

Would this help?

This says "followed by" ! or ; but I just tried it and it seems to be "preceded by".  Think this is why you can copy/paste configs that have leading ! spacers and those are ignored on the config input.

 

https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/fundamentals/configuration/15_sy/fundamentals-15-sy-book/cf-cli-search.html

 

"Note


Characters followed by an exclamation mark (!) or a semicolon (;) are considered as a comment and hence they are ignored in a command."


The post is in the context of UCOS CLI and not IOS,/IOS-XE. Good effort though.

Since you use SecureCRT and VBScript you can comment in the script code as much as you want. But not actually in what you send to the CVOS CLI. Not sure where you'd want the comments to appear, do you want them in just the script for easier changes down the line when you'd want to change something in the script or do you want it to appear in the log file? The later should likely be possible with separate code in the script itself that writes to the log file in sync with what you send to CLI.



Response Signature


Yes, that's right, I was using the log file as the results.  Then I would run sed or awk on it and/or import it into a spreadsheet to extract whatever I was looking for, and create my final results.  Sometimes I give the log to someone else for them to see results. 

Often I need to let myself know on the other end, what machine I'm talking to, or what values I'm sending to it, or even why I'm doing something in the script.  I already do plenty of notation in the VB script, but that doesn't help me when I'm analyzing the log file.  I supposed I could figure out how to write extra stuff to the log file, but it's actually pretty nice to know that the log file is what happened in SSH, period. 

 

I guess for now I'll keep putting '==' before any notes I want to make, and just live with the "invalid command" error afterwards.

I really do find it hard to believe they created a command line interface without any comment ability.  I guess I just have to accept that. 

 

thanks for you response and suggestion. 

Realised that I didn’t get back to this thread. If it’s the log file you want to see your comments in why not build the code for this within your VBS code? You don’t have to send it to the actual CLI for it to be apart of the log.



Response Signature


Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: