LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-27-2017, 02:28 PM   #1
pradeepspa
Member
 
Registered: Oct 2015
Posts: 79

Rep: Reputation: Disabled
Bash script to parse Output


Hello All,

This is my code ,

Code:
#!/bin/bash
Output=` snmpwalk -m /usr/share/snmp/mibs/CISCO-UNIFIED-COMPUTING-STORAGE-MIB.my -v2c -c opennms-Priv x.x.x.x .1.3.6.1.4.1.9.9.719.1.45.4.1.18 2>/dev/null | awk '{print $4}' | while read -r line ; do echo "Drive:$line" ;  done`

printf '%s\n' $Output

For this I am getting output similar to this,

Quote:
Drive online(1)
Drive online(1)
Drive online(1)
Drive online(1)
Drive online(1)

I am trying to modify the code to display like,

Quote:
Drive1 online(1)
Drive2 online(1)
Drive3 online(1)
Drive4 online(1)
Drive5 online(1)

Could someone guide me what needs to be added in code to achieve above result?
 
Old 01-27-2017, 02:37 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Code:
Output=$(snmpwalk -m /usr/share/snmp/mibs/CISCO-UNIFIED-COMPUTING-STORAGE-MIB.my -v2c -c opennms-Priv x.x.x.x .1.3.6.1.4.1.9.9.719.1.45.4.1.18 2>/dev/null | awk '{print $4}' | let i=1; while read -r line ; do echo "Drive $i:$line"; ((i++)); done)
Something like that?
 
Old 01-27-2017, 02:44 PM   #3
pradeepspa
Member
 
Registered: Oct 2015
Posts: 79

Original Poster
Rep: Reputation: Disabled
Thats exactly what i was expecting. Thanks for the quick help. I appreciate it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] BASH script to parse data from /dev/xxx and output to command atcom Programming 4 02-28-2015 10:59 AM
[SOLVED] parse file and use output to run a script johnthrax Programming 4 06-13-2013 09:40 AM
[SOLVED] Shell script help needed to parse ntpd -q output gkasica Programming 4 03-31-2012 06:19 AM
[shell script] execute command and parse output stoiss Programming 2 01-26-2009 01:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration