Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reporting disk usage with df -vk command 1

Status
Not open for further replies.

Marcel1958

Technical User
Oct 11, 2001
38
0
0
NL
Hello experts,

I have to report (by email) on a daily basis(using the df -vk command):

1 the total amount of disk usage
2 signal if the usage of a file system is > 80%

Who can help me with a usefull script?

Regards

Marcel
 
Is this sort of thing any good?

#!/bin/ksh
clear
echo " Checking File Systems"
echo
echo "Mount Total Used Free Used% Test"
echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
df -k |grep /| awk '{$2 = $2 /1000; $3 = $3 /1000 ; {if ($5>80 || $5=="100%") $
9 = "warning"}; $4 = $4 /1000; printf "%-15s " "%8.1f Mb " "%
8.1f Mb" "%8.1f Mb\t%5s%10s\n" ,$6, $2, $3,$4,$5,$9}'|sort
echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
echo
echo "Check file systems with warning"
echo

Greg.
 
Should have explained a bit.

This script uses df -k. If you want to use df -vk (which gives a different output column structure) then you'll need to change the awk script to manage the columns correctly.

If you want to mail the output, you can do something like <scriptname> | mail <username>

Greg.
 
Thanks Greg for your response.

As you can see is the result of the command not correct. I have included the result of the df -k command. Can you help me further and also explain the command.



Checking File Systems

Mount Total Used Free Used% Test

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1% 65.5 Mb 62.6 Mb 0.0 Mb 76
1% 655.4 Mb 649.7 Mb 0.0 Mb 22
1% 1048.6 Mb 1039.0 Mb 0.0 Mb 149 warning
1% 2031.6 Mb 1071.4 Mb 0.0 Mb 1555 warning
1% 6291.5 Mb 1224.3 Mb 0.1 Mb 82 warning
1% 6291.5 Mb 1536.2 Mb 0.1 Mb 3597 warning
1% 6291.5 Mb 1879.9 Mb 0.1 Mb 14055 warning
1% 6291.5 Mb 3417.1 Mb 0.0 Mb 63
1% 132644.9 Mb 31997.4 Mb 0.1 Mb 296 warning
2% 6291.5 Mb 1220.8 Mb 0.1 Mb 24827 warning
4% 245.8 Mb 102.0 Mb 0.1 Mb 4214 warning
6% 131.1 Mb 129.3 Mb 0.0 Mb 411 warning
6% 4030.5 Mb 1642.0 Mb 0.1 Mb 60320 warning
7% 49.2 Mb 16.6 Mb 0.1 Mb 748 warning

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Check file systems with warning

# df -k
Filesystem 1024-blocks Free %Used Iused %Iused Mounted on
/dev/hd4 245760 102004 59% 4214 4% /
/dev/hd2 4030464 1641972 60% 60320 6% /usr
/dev/hd9var 2031616 1071404 48% 1555 1% /var
/dev/hd3 65536 62616 5% 76 1% /tmp
/dev/hd1 49152 16616 67% 748 7% /home
/dev/lv00 6291456 1879888 71% 14055 1% /data01
/dev/lv01 6291456 1220748 81% 24827 2% /data02
/dev/lv02 6291456 1224332 81% 82 1% /data03
/dev/lv03 6291456 3417100 46% 63 1% /data04
/dev/lv04 6291456 1536204 76% 3597 1% /data05
/dev/tsm_lv 132644864 31997384 76% 296 1% /tsm
/dev/lvpd 1048576 1039020 1% 149 1% /var/pd
/dev/lvpsf 131072 129320 2% 411 6% /var/psf
/dev/lvpsfs 655360 649704 1% 22 1% /var/psf/segments
 
I need also the totals of the free and used blocks.
 
Hi,

With HP, the df -vk give output like :

hp>df -kv .
[tt]/tmp (/dev/vg00/lvol6 ) : 62414 total allocated Kb
47592 free allocated Kb
14822 used allocated Kb
23 % allocation used
[/tt]

You can use the following awk script :

dfvk.awk

function PrintInfos( sts) {
if (FileSystem != &quot;&quot;) {
sts = &quot;&quot;;
if (PUsed > 80) sts = &quot;WARNING&quot; ;
printf OutFmt, FileSystem, Total, Free, Used, PUsed, sts;
}
}
BEGIN {
OutFmt = &quot;%-24s %8s %8s %8s %3s %% %s\n&quot; ;
printf OutFmt,&quot;FileSystem&quot;,&quot;Total&quot;,&quot;Free&quot;,&quot;Used&quot;, &quot;&quot;, &quot;&quot; ;
}
{
InfoField = NF-3;
}
/ total allocated/ {
PrintInfos() ;
FileSystem = $1 ;
Total = $InfoField;
}
/ free allocated/ {
Free = $InfoField;
}
/ used allocated/ {
Used = $InfoField;
}
/ % allocation used/ {
PUsed = $InfoField;
}
END {
PrintInfos() ;
}

Example:

hp0> df -vk | awk -f dfvk.awk
[tt]FileSystem Total Free Used %
/home 19354 17782 1572 8 %
/opt 502263 148106 354157 70 %
/tmp 62414 47592 14822 23 %
/usr 812434 102422 710012 87 % WARNING
/var 806609 190461 616148 76 %
/stand 75359 47458 27901 37 %
/ 137423 89168 48255 35 %
[/tt] Jean Pierre.
 
As Jean Pierre said, these scripts are somewhat platform dependent. The one I posted was for Solaris. What platform are you using?

Greg.
 
Thanks Jean Pierre and Greg for your response.

We are running AIX 4.3.3

Marcel
 
Greg,

I tried running your script and got the following messages:
Checking File Systems

Mount Total Used Free Used% Test

diskmon: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xx: not found
awk: syntax error near line 2
awk: illegal statement near line 2
awk: newline in string near line 3
awk: syntax error near line 4
awk: illegal statement near line 4

diskmon: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xx: not found

Check file systems with warning


Do I kick off the script (called diskmon) as the name or with awk in command line such as:[tt]
#diskmon[/tt]

#df -k | awk -f diskmon[/tt]
Both didnt work for me.

Please advise what I am doing wrong?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top