Operating System - HP-UX
1848569 Members
6679 Online
104033 Solutions
New Discussion

Re: question on xargs and script

 
SOLVED
Go to solution
NOreen Merrick
Frequent Advisor

question on xargs and script

Hi Guys,

i think this is easy for you. I want to send the output of 'bdf' to a file and line it up as follows e.g.

used Mounted on
17% /
22% /stand
80% /var

etc

instead of

17% / 22% /stand 80% /var

so I can then manipulate the out in a for loop

Do you know how ?
is it xargs, someone said it is but dont know how to use xargs and man page is horrible on this one.

this is the core line frm script

echo `bdf | awk ' {print $5, $6 }'`> file1

and then I want to manipulate file1

Thanks

Noreen
13 REPLIES 13
Peter Godron
Honored Contributor
Solution

Re: question on xargs and script

Noreen,
but you are there already:

remove the echo part!
bdf | awk ' {print $5, $6 }' > file1

gives you something like
%used Mounted
80% /
20% /stand
36% /var
95% /usr
Hein van den Heuvel
Honored Contributor

Re: question on xargs and script

>> this is the core line frm script
>> echo `bdf | awk ' {print $5, $6 }'`> file1

Noreen,

That line by itself would do exactly what you request. Something else down the pipes must be doing the re-arranging. If there is an xargs 'down the pipes' that could cause this, not solve this.

free advice:

- Is your script ready to deal with cases where the bdf line is split into two for long names?

- You mention subsequent processing in a for loop. Can awk (or perl) not do it all, right there and then? It is looping, it sees all the fields, let it do all the work!

Regards,
Hein van den Heuvel
A. Clay Stephenson
Acclaimed Contributor

Re: question on xargs and script

There is a much easier way to accomplish your task. First use Bill's attached script, bdfmegs, rather than bdf because it fixes a problem that you haven't anticipated. Download bdfmegs, make it executable, and put in somewhere in your PATH.

then all you need to do is:
bdfmegs | awk '{ if ($0 ~ "^File System") next; print $(NF - 1)," ",$NF }' > file1

If it ain't broke, I can fix that.
Sandman!
Honored Contributor

Re: question on xargs and script

As Peter says remove the echo. One thing to note is that if device names are long then bdf output will wrap onto next line so try the construct below:

# bdf | awk '{if(NF>1) print $(NF-1), $NF}'
NOreen Merrick
Frequent Advisor

Re: question on xargs and script

Hi Hein/Peter,

great I understand.

Hein

what do you mean
"Is your script ready to deal with cases where the bdf line is split into two for long names?"

N



A. Clay Stephenson
Acclaimed Contributor

Re: question on xargs and script

That is what bdfmegs handles for you. bdf was designed to display in 80 columns so that if you have long mountpoint names or long filesystem names (think NFS) then the output is broken into 2 shorter lines. bdfmegs keeps every thing in 1 line in all cases.
If it ain't broke, I can fix that.
NOreen Merrick
Frequent Advisor

Re: question on xargs and script

Hi A Clay,


I don't have the bdfmegs on my machine?

Noreen
A. Clay Stephenson
Acclaimed Contributor

Re: question on xargs and script

It's a script that Bill Hassell wrote which cleans up the raw bdf output. If you had carefully examined my first posting in this thread, you would have seen the little paperclip -- the bdfmegs attachment.
If it ain't broke, I can fix that.
NOreen Merrick
Frequent Advisor

Re: question on xargs and script

Hi A Clay,

"Carefully read your response "???

I know what you mean now. I was confused by the command

bdfmegs | awk '{ if ($0 ~ "^File System") next; print $(NF - 1)," ",$NF }' > file1

I thought bdfmegs was a command on it's own and not the script, but now I see you said placed "in path". There I was googling "man bdfmegs"

Anyway I think this line will do me ok for what I want

CRITICALFSYSTEMS=`df -k | awk '{print $6, $5}' | grep [5-9][0-9]`


However is it ok to exceute this script on a live system or would that be very wreckless??


Thanks

Noreen
A. Clay Stephenson
Acclaimed Contributor

Re: question on xargs and script

It's safe to run df or bdf anytime so your command is safe. You should note that your varaible might contain multiple lines so that you may not get what you expect at all times. Your grep also leaves something to be desired.

In any event, I have a script that I have used for many years. Normally, it produces disk alerts for ITO/VPO/OVO -- whatever the HP Name of the Month for the same product is - but I modified to simply echo to stdout.

It consists of 2 files:
1) check_disk_space.sh -- this attachment
and
2) /root/conf/check_disk_space.conf -- I'll attach in the next posting. The .conf file allows you to set a threshold value for each filesystem of interest. For example, you might get concerned if /u01 is at 45% while /u02 might be set at 90%.

This should be very close to your needs -- and because I was lazy (or smart, take your pick) I chose to use bdfmegs rather than bdf. It's also wise to limit yourself to local filesystems because you typically handle NFS filesystem capacity issues on their local host.

In any event, here is the script, check_disk_space.sh:
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: question on xargs and script

and here is the configuration file, /root/conf/check_disk_space.conf:
If it ain't broke, I can fix that.
NOreen Merrick
Frequent Advisor

Re: question on xargs and script

Great thanks,

this will help me learn some stuff am knew to scripting.
Noreen
NOreen Merrick
Frequent Advisor

Re: question on xargs and script

Closing