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, 03: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, 03:37 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

Rep: Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653
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, 03: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 11:59 AM
[SOLVED] parse file and use output to run a script johnthrax Programming 4 06-13-2013 10:40 AM
[SOLVED] Shell script help needed to parse ntpd -q output gkasica Programming 4 03-31-2012 07:19 AM
[shell script] execute command and parse output stoiss Programming 2 01-26-2009 02:49 AM

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

All times are GMT -5. The time now is 08:12 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration