- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- awk Query.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 07:17 PM
05-02-2006 07:17 PM
awk Query.
ssh -q abcxyz 'bdf /var /tmp'|awk -v sd=nxdrpap3 '{print sd} /^\/dev/ {print $0}'
abcxyz
abcxyz
/dev/vg00/lvol7 2048000 1705778 321956 84% /var
abcxyz
/dev/vg00/lvol5 1024000 542751 452955 55% /tmp
I want it to be as follows.
abcxyz
/dev/vg00/lvol7 2048000 1705778 321956 84% /var
/dev/vg00/lvol5 1024000 542751 452955 55% /tmp
How do I put awk statement then?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 07:32 PM
05-02-2006 07:32 PM
Re: awk Query.
ssh -q abcxyz 'bdf /var /tmp'|awk -v sd=nxdrpap3 'BEGIN {print sd} /^\/dev/'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 07:40 PM
05-02-2006 07:40 PM
Re: awk Query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 07:50 PM
05-02-2006 07:50 PM
Re: awk Query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 07:57 PM
05-02-2006 07:57 PM
Re: awk Query.
Above, I want FS more than 85%, and there are none. But your awk contruct will still print abcxyz. I do not want that. If no FSs are more than 85%, it should not print anything at all, Else print hostname and FSs that are more than threshold specified.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 08:19 PM
05-02-2006 08:19 PM
Re: awk Query.
ssh -q awhq7135 'bdf /var /tmp' | awk '/^\/dev/{if($(NF-1)>90)print $0}' |
awk -v sd=nxdrpap3 '{if(NR==1)print sd"\n"$0;else print $0}'
The first awk pipe filters out the FS based on the >50% criterion and the second awk pipeline prints out the hostname and those FS's that are >50% capacity otherwise it prints nothing.
hope it helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 08:22 PM
05-02-2006 08:22 PM
Re: awk Query.
ssh -q abcxyz 'bdf /var /tmp' | awk '/^\/dev/{if($(NF-1)>50)print $0}' |
awk -v sd=nxdrpap3 '{if(NR==1)print sd"\n"$0;else print $0}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 08:51 PM
05-02-2006 08:51 PM
Re: awk Query.
Wrong outout-
lmnop
00:00:01 00:00:01 device %busy avque r+w/s blks/s avwait avserv
02:30:00 c55t3d6 76.55 17.41 36 3311 253.57 101.92
abcxyz
00:00:00 00:00:00 device %busy avque r+w/s blks/s avwait avserv
I should get only
lmnop
00:00:01 00:00:01 device %busy avque r+w/s blks/s avwait avserv
02:30:00 c55t3d6 76.55 17.41 36 3311 253.57 101.92
I am using following.
for i in lmnop abcxyz
do
remsh ${i} 'cat /var/adm/sa/sar02'|/usr/bin/sed -n '/device/,/Average/p'|egrep -iv "^$|Average"|awk '/^[0-9][0-9
]:/{t=$1} /avserv$/;{if (NR==1 || (NF==8 && $(NF-1)>250) || (NF==7 && $(NF-1)>250)) print t,$0}'|egrep -v '^[0-
9][0-9]:[0-9][0-9]:[0-9][0-9] device'|awk '{if ($NF>50) print $0}'|awk '{if ($3>50) print $0}'|awk -v sd=${i}
'{if(NR==1)print sd"\n"$0"\n";else print $0}'
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 09:37 PM
05-02-2006 09:37 PM
Re: awk Query.
to output conditionally, collect your data in an array. My example is based on the original bdf-question:
bdf -l |
awk -v h=hp9 -v lim=85 '/^\/dev/ {lev=substr($(NF-1),1,length($(NF-1)-1))+0;
if(lev>lim) l[++n]=$0}
END {if(n) {print h;for(j=1;j<=n;j++) print l[j]}}'
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2006 12:57 AM
05-03-2006 12:57 AM
Re: awk Query.
after reviewing your request of sar-data, I suggest to perform the whole task in awk (set your busy+avwait limits to your needs):
for h in host1 host2
do
remsh $h -n cat /var/adm/sa/sar02 |
awk -v busy=5 -v wait=7 -v h=$h '$2 == "device" {report=1;header=$0;next}
/^Average/ {report=0;next}
NF && report {if(($(NF-5)+0 >busy) || ($(NF-1)+0 >wait)) l[++n]=$0 }
END {if(n) {print h;print header;for(j=1;j<=n;j++) print l[j]}}'
done
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2006 02:45 AM
05-03-2006 02:45 AM
Re: awk Query.
As you go, remember the header lines.
Then when the reporting condition is triggered, print the header if not yet printed and print the trigger line.
Sticking to the df example, using the sd header variable itself as the flag:
# df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hda2 60928 60928 0 100% /
/dev/hda3 54405 43810 10595 81% /mnt
/dev/hda1 1743 1571 172 90% /boot
/dev/loop0 979 15 914 2% //mnt/root # df | awk -v sd=abc '/Use%/ {sd = sd "\n" $0} /^.dev/ && ($(NF-1) > 99) { if (sd) { print sd; sd=""} print} '
# df | awk -v sd=abc '/Use%/ {sd = sd "\n" $0} /^.dev/ && ($(NF-1) > 80) { if (sd) { print sd; sd=""} print} '
abc
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hda3 54405 43810 10595 81% /mnt
/dev/hda1 1743 1571 172 90% /boot
Using a seperate flag this looks like:
df | awk -v sd=abc '/Use%/ {sd = sd "\n" $0} /^.dev/ && ($(NF-1) > 80) { if (!header++) { print sd } print} '
That is, when the condition is met, test and increment header. If it was not true (0) then print header text. From now on it is no longer zero no matter how many more lines print.
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2006 02:52 AM
05-03-2006 02:52 AM
Re: awk Query.
bdf|awk -v PCT=60 'NR==1||substr($5,1,index($5,"%")-1)+0>=PCT' >> daily_${dcheck
}_$(hostname).log
(This will show all filesystems that are in use above 60%)
No points pls. This is what i used from one of our members here on the forums sometime back.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2006 08:15 PM
05-03-2006 08:15 PM
Re: awk Query.
I'm the author:
# Show mount points over PCT
bdf|awk -v PCT=90 'NR==1||substr($5,1,index($5,"%")-1)+0>=PCT'
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2008 08:00 AM
03-26-2008 08:00 AM
Re: awk Query.
bdf|awk -v PCT=90 'NR==1||substr($5,1,index($5,"%")-1)+0>=PCT'
I found the above posting very useful and really nice for what I needed to do but do not get why the +0 is needed. works the same without +0.Could you please explain it?
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2008 10:03 PM
03-26-2008 10:03 PM
Re: awk Query.
Peter had it first.
>but do not get why the +0 is needed. works the same without +0.
Two possible reasons.
1) To convert to numeric so a string compare isn't done.
2) To handle the case of substr returning an empty string?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2008 10:18 PM
03-26-2008 10:18 PM
Re: awk Query.
just out of curiosity, i ran the command and this does not seem to work!!
SRV2:>bdf /d01
Filesystem kbytes used avail %used Mounted on
/dev/vgappinst/lv_appinst
20963328 20062972 900356 96% /d01
SVR2:>bdf|awk -v PCT=90 'NR==1||substr($5,1,index($5,"%")-1)+0>=PCT'
Filesystem kbytes used avail %used Mounted on
SVR2:>
did i miss anything?
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2008 10:24 PM
03-26-2008 10:24 PM
Re: awk Query.
I think i found my mistake!
When the row of the bdf output for a specific file system spans over more than 1 line, it does not work!
tried the same but with bdfmegs
SRV2:home/yogeeraj>./bdfmegs|awk -v PCT=90 'NR==1||substr($5,1,index($5,"%")-1)+0>=PCT'
File System Mbytes Used Avail %Used Mounted on
/dev/vgpfsdb01/lv_pfsdb01 20472 20365 105 99% /d10
/dev/vgappinst/lv_appinst 20472 19593 879 96% /d01
/dev/vgorarestore/lv_orarestore 35828 33831 1997 94% /RESTORE
SRV2:home/yogeeraj>
kind regards
yogeeraj