Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I'm trying to parse the input of 1 command set into 3 separate files.
Running ciscocmd program with 3 commands listed in a command file - show cdp nei, show vtp status and show tech.
The script goes out and runs the commands on the devices and then sends the output back to the screen or to a batch file for further processing line by line until the entire job is complete.
OutPut ex.
TEC-2950-2#show cdp nei
Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge
S - Switch, H - Host, I - IGMP, r - Repeater, P - Phone
Device ID Local Interface Holdtme Capability Platform Port ID
TEC-XXXX-2
Gig 0/1 129 R S I WS-XXXXX Gig 2/3
TEC-2950-2#show vtp status
VTP Version : 2
Configuration Revision : 89
Maximum VLANs supported locally : 250
Number of existing VLANs : 60
VTP Operating Mode :
VTP Domain Name :
VTP Pruning Mode :
VTP V2 Mode :
VTP Traps Generation :
MD5 digest :
Configuration last modified by x.x.x.x at 1-22-08 19:10:35
TEC-XXXX-2#
My batch:
#!/bin/sh
#
# mybatch
while read line
do echo "$line" >> $CISCOHOST.txt
Which outputs everything into a file.
What I'd like to have is $CISCOHOST-show_cdp_nei.txt and $CISCOHOST-show_vtp_status.txt .... files
Would it be easier to parse from a file or from the input as it's coming in?
If you're running the batch and it's executing the commands remotely, you could just split the output based on the command execution.
If I'm misunderstanding and you're just getting the output back with the command name, it would be just as easy to parse while the info's coming back as it would parsing a file. The only thing I'm not sure about, with the cisco is whether your real-time tty echo's that you get back don't sometimes get clogged or jammed up, in which case parsing the final file would be the way to go about it.
Sorry if that's more confusing than helpful. If you have anything more specific, please post and I'd be glad to look.
There are two files ciscocmd and mybatch.
The ciscocmd funnels the output to the batch file, and the batch file conducts further processing on the stream.
I'm not sure how to split the stream based on the commands.
For instance I'd like to maybe save the entire stream to a variable or array and then say get and print all of the information (each line) from "show cdp nei" to the line before "show vtp status", and save to $CISCOHOST-show_cdp_nei.txt.
How would I parse the information in the variable or array? I just can't seem to figure it out.
The script ran but no output files where generated.
The ciscocmd uses expect to reach the devices, run the commands and gather the results. The results are then sent back line by line, exported via the cat command to a tmp file and then piped to the batch file.
I thought about using a while within a while or storing everything in a container and then enacting some type of awk against it?
Yeah, looks like the same issue. The $\r should probably be $r. Try it without the $.
If you echoed through that array and it all came out on one line, the array probably only has one value, which is everything (normally, the \r would be a line separate, but you have $\r
It almost has to be getting goofed before you parse it because if I put your output in a file, and the run the batch I put up before, I get this:
-bash-3.2$ cat X|./Y
-bash-3.2$ ls -tr
showvtpstatus.file showcpdnei.file
-bash-3.2$ cat show*
TEC-2950-2#show cdp nei
Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge
S - Switch, H - Host, I - IGMP, r - Repeater, P - Phone
Device ID Local Interface Holdtme Capability Platform Port ID
TEC-XXXX-2
Gig 0/1 129 R S I WS-XXXXX Gig 2/3
TEC-2950-2#show cdp nei
Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge
S - Switch, H - Host, I - IGMP, r - Repeater, P - Phone
Device ID Local Interface Holdtme Capability Platform Port ID
TEC-XXXX-2
Gig 0/1 129 R S I WS-XXXXX Gig 2/3
VTP status
VTP Version : 2
Configuration Revision : 89
Maximum VLANs supported locally : 250
Number of existing VLANs : 60
VTP Operating Mode :
VTP Domain Name :
show tech binger
VTP Pruning Mode :
VTP V2 Mode :
VTP Traps Generation :
MD5 digest :
Configuration last modified by x.x.x.x at 1-22-08 19:10:35
TEC-XXXX-2#
VTP status
VTP Version : 2
Configuration Revision : 89
Maximum VLANs supported locally : 250
Number of existing VLANs : 60
VTP Operating Mode :
VTP Domain Name :
VTP Pruning Mode :
VTP V2 Mode :
VTP Traps Generation :
MD5 digest :
Configuration last modified by x.x.x.x at 1-22-08 19:10:35
TEC-XXXX-2#
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.