Exercise 3 on lab 8 done

This commit is contained in:
Jack-Benny Persson 2013-12-28 15:19:25 +01:00
parent 3a13dae36a
commit 78e47a91e3
2 changed files with 43 additions and 0 deletions

2
Labb8/diskusage.sed Normal file
View File

@ -0,0 +1,2 @@
1d
s/\%//

41
Labb8/ovning3.sh Executable file
View File

@ -0,0 +1,41 @@
#!/bin/bash
# Jack-Benny Persson
# LX13
# Exercise 3, lab 8 (Write a script to warn when disk usage exceeds 80%)
# Binaries
Df="/bin/df"
Sed="/bin/sed"
Awk="/usr/bin/awk"
Logger="/usr/bin/logger"
# Variables
DiskSed="diskusage.sed"
Warn=80
# Sanity checks
for Bin in $Df $Sed $Awk $Logger; do
if [ ! -x $Bin ]; then
echo "Can't execute $Bin"
exit 1
fi
done
# Put the usages in an array
Usages=(`$Df -h | $Awk '{print $5}' | $Sed -f $DiskSed`)
# Put all the disknames in an array
Disks=(`$Df -h | $Awk '{print $1}'| $Sed '1d'`)
# Start the loop to check the disk usage
Index=0
for i in ${Usages[@]}; do
if [ $i -gt $Warn ]; then
echo "Disk ${Disks[$Index]} is ${i}% full" >&2
$Logger "Disk ${Disks[$Index]} is ${i}% full"
fi
((Index++))
done
exit 0