1833589 Members
3672 Online
110061 Solutions
New Discussion

shell script

 
SOLVED
Go to solution
vas  bolpali
Advisor

shell script

Hi guys,

the output of "df -k" is giving the following output.
/home (/dev/vg02/lvol2 ) : 17364312 total allocated Kb
2772080 free allocated Kb
14592232 used allocated Kb
84 % allocation used
/usr (/dev/vg00/lvol7 ) : 1471160 total allocated Kb
1034935 free allocated Kb
436225 used allocated Kb
29 % allocation used



I want as followes.
/home /usr
84 % 29 %


can some body suggest the shell script?
the script must use 'df' command ( not 'bdf').
Thnx in advance.
VB
keeping you ahead of the learning curve
4 REPLIES 4
John Palmer
Honored Contributor

Re: shell script

Hi,

Try the following but you may have to adjust the printf statements to cater for the maximum length filesystem name that you have (I have allowed only 10 chars...

#!/usr/bin/sh

let NUM=0

df -k | {
while read A B C
do
if [[ ${A} = /*(?) ]];
then MP[NUM]=${A}
continue
fi

if [[ ${B} = % ]];
then PCT[NUM]=${A}
let NUM=NUM+1
continue
fi
done
}

let TOTAL=NUM

let NUM=0
while ((NUM < TOTAL));
do
printf "%10s" ${MP[NUM]}
let NUM=NUM+1
done

print

let NUM=0
while ((NUM < TOTAL));
do
printf "%9s\%" ${PCT[NUM]}
let NUM=NUM+1
done

print

exit

Regards,
John
John Dvorchak
Honored Contributor
Solution

Re: shell script

#!/bin/ksh
echo "/home /usr"
HOM=`df -k /home|grep %|awk '{print $1}'`
USR=`df -k /usr |grep %|awk '{print $1}'`
echo "$HOM % $USR %"

Sorry my first example was for /var and /usr. But now you can compare them both and see that there isn't much to make if work for any filesystem or any number of file systems.
If it has wheels or a skirt, you can't afford it.
John Dvorchak
Honored Contributor

Re: shell script

#!/bin/ksh
echo "/var /usr"
VAR=`df -k /var|grep %|awk '{print $1}'`
USR=`df -k /usr |grep %|awk '{print $1}'`
echo "$VAR % $USR %"


This should work for you.
If it has wheels or a skirt, you can't afford it.
Kellogg Unix Team
Trusted Contributor

Re: shell script

How about using the following -

bdf /home /usr

...Manjeet
work is fun ! (my manager is standing behind me!!)