How to: Grep certain info from HWinfo


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to: Grep certain info from HWinfo
# 1  
Old 08-09-2012
How to: Grep certain info from HWinfo

Just a noob here trying to get some help Smilie

I am in need of certain information from multiple servers. These servers are Dell PowerEdges with OpenSuSE 10.2 to 11.3.

Here are some lines from /usr/sbin/hwinfo and information I need from those lines:

OEM id: "DELL"
Product: "PowerEdge 850"
Serial: "5GTKL94"

Here are some lines from /proc/cpuinfo and information I need from those lines:

I need total number of cpu cores (16 core)
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4

Here are some lines from /proc/meminfo and information I need from those lines:

If possible display RAM as GB (8 GB)
MemTotal: 8185084 kB

Here are some lines from "df -h" command and information I need from those lines:

Filesystem Size Used Avail Use% Mounted on
/dev/md0 72G 63G 9.2G 88% /



I also need this information but do not have a command to show it yet:
  • Hard Drive Model
  • # of Hard Drives


Any help is appreciated!

Cheers Smilie
# 2  
Old 08-09-2012
"grep" will not help you (at least not "grep" alone), because grep filters lines with some patterns in it from a text - nothing less, nothing more. It can either display these filtered lines or count them, but that's it.

But as luck will have it, there are more tools in the Unix toolbox than just "grep" and solving your problem is easy:

Code:
OEM id: "DELL"
Product: "PowerEdge 850"
Serial: "5GTKL94"

In this case you have to filter certain parts of the lines. You can use sed, awk or similar tools for this, but i prefer pure shell code, as this runs by far fastest (i simulate your utility by a simple "cat" and a here-document, which will give the output. Replace this with your original command):

Code:
(cat <<EOF
OEM id: "DELL"
Product: "PowerEdge 850"
Serial: "5GTKL94"
EOF) |\
while read LINE ; do
     LINE="${LINE#*\"}"     # chop off everything up to the first double quote
     LINE="${LINE%\"*}"     # chop off everything after the last double quote
     print - "$LINE"
done

The CPU count is a little more tricky, because you have to sum. Use "awk" for such things:

Code:
(cat <<EOF
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
EOF) |\
awk 'BEGIN {sum=0;} {sum+=$4;} END {printf( "%2d\n", sum);}'

The next is a combination of line filter and cutting some text from the line. You can use "sed" for such things:

Code:
(cat <<EOF
If possible display RAM as GB (8 GB)
MemTotal: 8185084 kB
EOF) |\
sed -n 's/^MemTotal: //p'

The last one is of the same form (line filter plus text cutting), hence the same approach:

Code:
(cat <<EOF
Filesystem Size Used Avail Use% Mounted on
/dev/md0 72G 63G 9.2G 88% /
EOF) |\
sed '1d;s/^.[^ ]* //;s/ .*$//'


To get the number of hdisks is a problem without knowing which hdisks you have: IDE disks are usually named differently than SCSI (SAS) disks, LUNs using one of the many FC-technologies (SDD, Multipath, Powerpath, and so on) often have even several names for the same disk (each way to the fabric gets its own name), etc..

Tell us, which disks you have or expect and we can tell you how to scan for these.

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

2. Shell Programming and Scripting

Grep/awk part of info of a column

I have a question that I am at a loss to solve. I have 3 column tab-separated data, such as: abs nmod+n+n-commitment-n 349.200023 abs nmod+n+n-a-commitment-n 333.306429 abs into+ns-j+vn-pass-rb-divide-v 295.57316 abs nmod+n+ns-commitment-n 182.085018 abs nmod+n+n-pledge-n ... (2 Replies)
Discussion started by: owwow14
2 Replies

3. Shell Programming and Scripting

need a one liner to grep a group info from /etc/group and use that result to search passwd file

/etc/group tiadm::345:mk789,po312,jo343,ju454,ko453,yx879,iy345,hn453 bin::2:root,daemon sys::3:root,bin,adm adm::4:root,daemon uucp::5:root /etc/passwd mk789:x:234:1::/export/home/dummy:/bin/sh po312:x:234:1::/export/home/dummy:/bin/sh ju454:x:234:1::/export/home/dummy:/bin/sh... (6 Replies)
Discussion started by: chidori
6 Replies

4. Shell Programming and Scripting

How to pull info under headers in file(awk,grep,while loop)

below is an extract from my file and I am trying to use Awk and grep and a while loop to pull infomation from under neath "HBA WWN=".HBA WWN=" reoccurs all over the file but the 100000c.....number are unique and I want to be able to pull and reference specifi information under this header ever time... (2 Replies)
Discussion started by: kieranfoley
2 Replies

5. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

6. Shell Programming and Scripting

Getting LV Info

I have this working ksh, and it returns like below: LOGICAL VOLUME: prod_2048_005 VOLUME GROUP: prod1vg TYPE: raw WRITE VERIFY: off PHYSICAL VOLUME: hdisk108 VOLUME GROUP: prod1vg TOTAL PPs: 1023 (130944 megabytes) VG DESCRIPTORS: 1 USED PPs: 904 (115712 megabytes) MAX REQUEST: 1 megabyte... (1 Reply)
Discussion started by: Daniel Gate
1 Replies

7. UNIX for Dummies Questions & Answers

Some Info.

Hiya all ... i am a newbie to UNIX, Just want to knwo what this command does: /sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' I think, 'grep shows the line with 'inet addr' (which is the 2nd line, displaying the IP Address, Broadcast Address and Subnet Mask) ... Is... (8 Replies)
Discussion started by: ad4m88
8 Replies

8. Shell Programming and Scripting

Need Info

Hi, I'm a oracle DBA with little knowledge of Unix. I wanted to write some shell scripts which will be helpful for DBA's regular activity. As i'm a new to oracle with unix can any plese tell me what are all the activities can be done throgh Unix Shell Scripts also suggest me how to learn... (1 Reply)
Discussion started by: msgobinathan
1 Replies

9. UNIX for Dummies Questions & Answers

Grep Info

What is NR this statement grep '^\{1,10\}$' $colfile | awk '{print "my_col_id("NR") := "$2";"}' >> $SQL_TEMP_FIL Thanks Pinky (1 Reply)
Discussion started by: pinky
1 Replies

10. UNIX for Dummies Questions & Answers

SU info

from the man page of su: EXAMPLES Example 1: Becoming User bin While Retaining Your Previously Exported Environment To become user bin while retaining your previously exported environment, execute: example% su bin Example 2: Becoming User bin and ... (4 Replies)
Discussion started by: afflack
4 Replies
Login or Register to Ask a Question