Re: script query

 
SOLVED
Go to solution
himacs
Super Advisor

script query

Hi Admins,

I require ur help finih below small script.
Actually its in solaris

1. for i in `df -h |awk '{print $1}'|grep -i /dev` -- it will give below output
/dev/dsk/c0t0d0s3
/dev/dsk/c0t1d0s4
/dev/dsk/c0t0d0s6

my query is.. A=`df -h $i |awk '{print $5}'`
output is
capacity
78%
I dont want 'capacity' to display.How to remove that heading..

Plz help on this

regards
himacs



11 REPLIES 11
James R. Ferguson
Acclaimed Contributor

Re: script query

Hi Himacs:

# A=$(df -h $i | awk 'NR>1 {print $5}')

...will skip the first line of the input.

Notice that instead of using backticks, I have used the Posix '$( ... )' syntax. It is clearer.

Regards!

...JRF...
himacs
Super Advisor

Re: script query

Hi ,

Below is my script

$ vi test
"test" 18 lines, 245 characters



for i in `df -h|awk '{print $1}'|grep -i /dev`

A=`(df -h $i |awk 'NR>1 {print $5}')`
B=`(df -h $i |awk 'NR>1 {print $6}')`
if [$A -gt 50]
then
echo " FS usage of $B is $A%"
fi


error is - ./test: syntax error at line 7: `A=`(df -h $i |awk 'NR>1 {print $5}')`' unexpected

i tried with $ with A line but error..

any body tells whats the wrong..


Actually i want to display the mountpoint which usage are more than 50..


regards
himacs
James R. Ferguson
Acclaimed Contributor

Re: script query

Hi (again):

HP-UX doesn't have the '-h' switch to 'df'. If you use 'bdf' you could do:

# cat ./myscript
#!/usr/bin/sh
bdf | awk 'NR>1' | while read X X X X A B
do
A=$(echo ${A} | sed -e 's/%//')
if [ $A -gt 50 ]; then
echo "FS usage of $B is $A%"
fi
done

...

Notice that whitespace surrounds the test (in square brackets). You repetively used an 'awk' to snip what you already had. Here, it's simpler to the shell do the read and split the line into fields. We need to snip the "%" character and we do that with a simple 'sed'.

Regards!

...JRF...
himacs
Super Advisor

Re: script query

HI JRF,

Thanx for the reply..

Actually this is for sun server..
I thought shell scripting is same for both the versions



regards
himacs
Tingli
Esteemed Contributor

Re: script query

In your script, your second line should be "do" instead of A=..... It is just a syntax error.
James R. Ferguson
Acclaimed Contributor
Solution

Re: script query

Hi (again) Himacs:

> Actually this is for sun server..
I thought shell scripting is same for both the versions

UNIX versions are variations of the AT&T System V and the Berkley BSD lines and differ in some of the commands they offer to accomplish the same task.

http://en.wikipedia.org/wiki/UNIX_System_V

http://en.wikipedia.org/wiki/BSD_UNIX

You should easily be able to modify my last script offering to accomodate your needs. UNIX and Linux variations might have minor differences but fundamentally they are all very similar.

Regards!

...JRF...
Julián Aimar
Frequent Advisor

Re: script query

Only one command,

Solaris

df -k | grep -v capacity | awk '($5>50) {print "FS usage of "$6" is "$5}'


HP-UX

bdf | awk '($5>50) {print "FS usage of "$6" is "$5}'

Buena suerte

JEA
jeevarajkn
Frequent Advisor

Re: script query

Hi Julian

Thanx

Above command is given the below output

bash-3.00$ df -k | grep -v capacity | awk '($5>75) {print "FS usage of "$6" is "$5}'
FS usage of / is 75%
FS usage of /platform/sun4v/lib/libc_psr.so.1 is 75%
FS usage of /platform/sun4v/lib/sparcv9/libc_psr.so.1 is 75%
FS usage of /reuters is 89%


is it possible to avoid " /platform", I want to grep only "/dev" filesystems.
Viktor Balogh
Honored Contributor

Re: script query

"is it possible to avoid " /platform", I want to grep only "/dev" filesystems."

Try this on Solaris:

# df -k | awk '! /capacity/ && ($5>75) && /\/dev/ {print "FS usage of "$6" is "$5}'

note the multiple conditions at the beginning of awk, this way you won't have to use grep and so it is more powerful.

****
Unix operates with beer.