Adding hostname on the output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding hostname on the output
# 1  
Old 02-06-2013
Adding hostname on the output

// AIX 6.1

HTML Code:
pcmpath query device |awk 'BEGIN{print "TYPE\tDEVICE NAME\tSERIAL\tSIZE"} /DEVICE/  {disk=$5
                     printf "%s\t", $7
                     printf "%s\t", disk
                     getline; printf "%s\t", substr($2, length($2)-3)
                     ("bootinfo -s " disk) | getline; print; sum+=$0
                    }
     END {print "TOTAL SIZE:", sum}'
I have this syntax working, and need to add the hostname of AIX node on each row on the output so that the output will like:

HTML Code:
TYPE    DEVICE NAME     SERIAL  SIZE HOSTNAME
1750500 hdisk2  100A    16384           rpsprod1
1750500 hdisk3  1010    73728           rpsprod1
1750500 hdisk4  1014    36864           rpsprod1
1750500 hdisk5  1015    36864           rpsprod1
1750500 hdisk6  101E    36864           rpsprod1
1750500 hdisk7  101F    36864           rpsprod1
Please advise.
# 2  
Old 02-06-2013
Code:
pcmpath query device |awk -v H="$HOSTNAME" 'BEGIN{print "TYPE\tDEVICE NAME\tSERIAL\tSIZE\tHOSTNAME"} /DEVICE/  {disk=$5
                     printf "%s\t", $7
                     printf "%s\t", disk
                     getline; printf "%s\t", substr($2, length($2)-3)
                     ("bootinfo -s " disk) | getline S; printf "%s\t%s\n", S, H; sum+=$0
                    }
     END {print "TOTAL SIZE:", sum}'

# 3  
Old 02-06-2013
Code:
pcmpath query device |awk 'BEGIN{print "TYPE\tDEVICE NAME\tSERIAL\tSIZE\tHOSTNAME"}
 /DEVICE/ {
            disk=$5
            printf "%s\t", $7
            printf "%s\t", disk
            getline; printf "%s\t", substr($2, length($2)-3)
            ("bootinfo -s " disk) | getline; printf "%s\t",$0; sum+=$0
            printf "%s\n", hostname
 }      END {print "TOTAL SIZE:", sum}' hostname=`uname -n`


Last edited by MadeInGermany; 02-06-2013 at 02:58 PM.. Reason: line feeds were garbled
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk remote multiple hosts print remote hostname and output

Hi all, i'm trying to gether multiple pattern on remote hosts, and trying to print hostname and the pattern, ssh remoteserver1 -C 'hostname 2>&1;cat /var/log/server1.log | awk -F ";" '"'"'{ print " "$2" "$5}'"'"'| sort | uniq -c | sort -g -r ' The output is the following, remoteserver1 ... (8 Replies)
Discussion started by: charli1
8 Replies

2. UNIX for Beginners Questions & Answers

Smbtree output, hostname?

Just playing about with Samba today, if I run smbtree on a couple of clients I get: WORKGROUP HOME \\P_151 Samba 4.5.12-Debian \\P_151\IPC$ IPC Service (Samba 4.5.12-Debian) \\P_151\Share Pi Share \\P_151\print$ ... (1 Reply)
Discussion started by: MuntyScrunt
1 Replies

3. UNIX for Advanced & Expert Users

Hostname -f hostname: Unknown host

deleted (0 Replies)
Discussion started by: hce
0 Replies

4. Shell Programming and Scripting

Adding and then separating the output

Hi I have this output /vol/vol0 4GB /vol/nonprod00 682GB /vol/prod00 3GB /vol/nasp_archive 201GB /vol/nasp_iface 92GB /vol/nasp_bsi 0GB /vol/nasp_vertex 0GB /vol/nasp_sapmnt_mp2 1GB /vol/nasp_sapmnt_prd 52GB /vol/nasp_sapmnt_srp 1GB /vol/nasp_smd 1GB /vol/nasp_ccms 0GB... (8 Replies)
Discussion started by: bombcan
8 Replies

5. Emergency UNIX and Linux Support

HP UX - ILO Console hostname different than Machine Hostname...

Hi All, So we added a new HP-UX 11.31 machine. Copied OS via Ignite-UX (DVD)over from this machine called machine_a. It was supposed to be named machine_c. And it is when you log in...however when I'm in the ILO console before logging in, it says: It should say: What gives? And how do... (4 Replies)
Discussion started by: zixzix01
4 Replies

6. Shell Programming and Scripting

adding hostname and date in subject of the mail

Hi Team, I coded my code to send mail to some reciepents with subject and date. Can somebody suggest me how to add host name to subject ? and the below code is correct for date ? my aim is to send mail with "subject in < hostname> on <date>".When i execute this script on my server its hung... (3 Replies)
Discussion started by: rocking77
3 Replies

7. Shell Programming and Scripting

Adding Text To |bc Output

Hello. I have this.. $ echo '2+2' | bc 4 But I want to output it as 4 MB So, can I achieve that through one single command line? Thank you. (7 Replies)
Discussion started by: aimy
7 Replies

8. Shell Programming and Scripting

adding another field to SED output

Dear experts, I have a file called "check" with contents like below i used the sed command like below to get the value of "success" and "failed" only My question is how can i get the value to include the time "03:15", so that i can get a value such as below : - Appreciate... (4 Replies)
Discussion started by: aismann
4 Replies

9. UNIX for Dummies Questions & Answers

Solaris - unknown hostname - how can I change hostname?

Hello, I am new to Solaris. I am using stand alone Solaris 10.0 for test/study purpose and connecting to internet via an ADSL modem which has DHCP server. My Solaris is working on VMWare within winXP. My WinXP and Solaris connects to internet by the same ADSL modem via its DHCP at the same... (1 Reply)
Discussion started by: XNOR
1 Replies

10. Shell Programming and Scripting

adding order number in the output file

Hello, I have a list of all order number like below: maryu01001 johnm00003 peter02234 catmy66751 For the above, all number must in 5 digits and I need to add one into the number and output a new list like below: maryu01002 johnm00004 peter02235 catmy66752 How can write a... (20 Replies)
Discussion started by: happyv
20 Replies
Login or Register to Ask a Question