I am trying a script which will alert if disk space crosses some threshold, i googled it and got some scripts already, but they are not working with my server.
The problem is, my filesystem names are big, so the sizes are moving to the second line. just like below
any ideas? thanks in advance
user@host:/ta/folder/folder/tmp> df -h
Filesystem Size Used Avail Use% Mounted on
/dev/folder/folder/folder
18G 3.1G 14G 19% /
devtmpfs 32G 136K 32G 1% /dev
tmpfs 32G 0 32G 0% /dev/shm
/dev/folder/folder 99M 50M 45M 53% /boot
/dev/folder/folder
4.0G 2.1G 1.7G 56% /tk
RudiC
January 11, 2013, 4:46am
2
Searching these forums would have allowed you to at least find a starting point. However, try
$ awk 'NF<6 {getline y; $0=$0 FS y} {print $5}' file
Use%
19%
1%
0%
53%
56%
thanks for the help,
this i accomplished, but when the script triggers a mail, i want to include which is the filesystem crossed this space???
any ideas??
thanks in advance
Print 5th & 6th column
$ awk 'NF<6 {getline y; $0=$0 FS y} {print $5,$6}' file
# df -h | awk 'NF<6 {getline y; $0=$0 FS y} {print $5,$6}'
Use% Mounted
31% /usr/bin
31% /usr/lib
31% /
98% /cygdrive/a
98% /cygdrive/b
31% /cygdrive/c
98% /cygdrive/d
98% /cygdrive/n
RudiC
January 11, 2013, 5:21am
5
karthikeayan:
thanks for the help,
this i accomplished, but when the script triggers a mail, i want to include which is the filesystem crossed this space???
any ideas??
thanks in advance
My proposal was meant to be a starting point for you to help yourself, not a final solution to a problem that was only rudimentarily specified.
I just wrote something working... give comments to improve myself!!!
#!/usr/bin/bash
df -k | grep -v -i "use" > /tmp/disk_space$$
awk '{
if (NF < 2)
{
print $0
}
}' /tmp/disk_space$$ >> /tmp/file_info01$$
awk '{
if (NF==5)
{
used_size=substr($4,0,length($4)-1);
print used_size;
}
}' /tmp/disk_space$$ >> /tmp/file_info02$$
paste /tmp/file_info01$$ /tmp/file_info02$$ > /tmp/file_info11$$
awk '{
if (NF==6)
{
used_size=substr($5,0,length($5)-1);
print $1,used_size
}
}' /tmp/disk_space$$ >> /tmp/file_info12$$
cat /tmp/file_info11$$ /tmp/file_info12$$ > /tmp/file_info$$
awk '{
if ($2>50)
{
print "Disk running out of space ------> ",$1,"------> "$2,"%"
}
}' /tmp/file_info$$
rm /tmp/file_info11$$
rm /tmp/file_info12$$
rm /tmp/file_info$$
rm /tmp/disk_space$$
RudiC
January 11, 2013, 6:06am
7
I'm not sure what you want to achieve with that many awk calls. Try to minimize those, and the costly fiddling with tmp files, almost everything can be done in one statement:
df -h|
awk 'NF<6 {getline y; $0=$0 FS y}
NR>1 && $5+0>50 {print "disk running out of space:", $5, ": ", $6}
'
could you please explain the above statement?
RudiC
January 12, 2013, 1:21am
10
df -h| # report file system disk space usage in human readable form
awk 'NF<6 {getline y; $0=$0 FS y} # repair wrapped lines
NR>1 && $5+0>50 # start with line 2: if field 5 (converted to number by +0) is greater than 50 (%) then...
{print "di ... ce:", $5, ": ", $6}
'