Create a script sends an email message to the user specified
Create a script sends an email message to the user specified on the command line if any of the file systems at more than 60% of capacity. The script should not process special file systems as /proc on the ce.uml.edu. It should only process file systems which are either locally mounted or are mounted via NFS.
An individual email should be sent for each filey system which is at the warning level (60%) There should be a subject on the email with a message \"Warning: File system <put file system the>here is at <X>% of capacity\" If the files system is at greater than 90% of capacity, the \"Warning\" should be changed to \"Critical Warning\".
You may use any scripting language including /bin/sh, ksh, bash, awk or perl. Work done in the C-Shell (csh) will not be accepted. The same program for this assignment must be able to be run on both CE.UML.EDU and CYBERSERVER.UML.EDU
Please upload the script for the assigment. Do not upload a Word Document. I may run the script on either or both of the machines to verify your work.
Example output of the df -k command on CE.UML.EDU
Filesystem kbytes used avail capacity Mounted on
/dev/dsk/c0t0d0s0 11089228 6593301 4385035 61% /
/proc 0 0 0 0% /proc
mnttab 0 0 0 0% /etc/mnttab
fd 0 0 0 0% /dev/fd
/dev/dsk/c0t0d0s5 6053358 1984237 4008588 34% /var
swap 3701808 80 3701728 1% /var/run
swap 3702784 1056 3701728 1% /tmp
/dev/dsk/c0t1d0s7 39608035 13478135 25733820 35% /backups
/dev/dsk/c0t1d0s0 30983686 4861760 25812090 16% /users
/dev/dsk/c0t0d0s7 51379263 14579685 36285786 29% /space
/space/local 51379263 14579685 36285786 29% /usr/local
/space/opt/SUNWspro 51379263 14579685 36285786 29% /opt/SUNWspro
This command -T shows the file system types, so you would only process ufs on this system
: /usr/local/bin/df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/dsk/c0t0d0s0
ufs 11089228 6593301 4385035 61% /
/dev/dsk/c0t0d0s5
ufs 6053358 1984246 4008579 34% /var
swap tmpfs 3701720 80 3701640 1% /var/run
swap tmpfs 3702696 1056 3701640 1% /tmp
/dev/dsk/c0t1d0s7
ufs 39608035 13478135 25733820 35% /backups
/dev/dsk/c0t1d0s0
ufs 30983686 4861760 25812090 16% /users
/dev/dsk/c0t0d0s7
ufs 51379263 14579685 36285786 29% /space
/space/local lofs 51379263 14579685 36285786 29% /usr/local
/space/opt/SUNWspro
lofs 51379263 14579685 36285786 29% /opt/SUNWspro
With that in mind on ce.uml.edu, you can run which will produce the correct file systems
: /usr/local/bin/df -t nfs -t ufs
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/dsk/c0t0d0s0 11089228 6593301 4385035 61% /
/dev/dsk/c0t0d0s5 6053358 1984246 4008579 34% /var
/dev/dsk/c0t1d0s7 39608035 13478135 25733820 35% /backups
/dev/dsk/c0t1d0s0 30983686 4861760 25812090 16% /users
/dev/dsk/c0t0d0s7 51379263 14579685 36285786 29% /space
Example output of the dk -k command on CYBERSERVER.UML.EDU
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/cyberserver-root 141716900 4354124 130266868 4% /
udev 504896 12 504884 1% /dev
tmpfs 102492 340 102152 1% /run
none 5120 0 5120 0% /run/lock
none 512452 0 512452 0% /run/shm
/dev/sda1 233191 26961 193789 13% /boot
ce.uml.edu:/users 30984192 4861952 25812992 16% /users
ce.uml.edu:/space 51380224 14579712 36286464 29% /space
This command shows the filesystem types, you would process ext4, ext2 and nfs on this system
: df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/mapper/cyberserver-root ext4 141716900 4354120 130266872 4% /
udev devtmpfs 504896 12 504884 1% /dev
tmpfs tmpfs 102492 340 102152 1% /run
none tmpfs 5120 0 5120 0% /run/lock
none tmpfs 512452 0 512452 0% /run/shm
/dev/sda1 ext2 233191 26961 193789 13% /boot
ce.uml.edu:/users nfs 30984192 4861952 25812992 16% /users
ce.uml.edu:/space nfs 51380224 14579712 36286464 29% /space
With that in mind on cyberserver.uml.edu, you can run
: df -t ext4 -t ext2 -t nfs
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/cyberserver-root 141716900 4354120 130266872 4% /
/dev/sda1 233191 26961 193789 13% /boot
ce.uml.edu:/users 30984192 4861952 25812992 16% /users
ce.uml.edu:/space 51380224 14579712 36286464 29% /space
Solution
#!/bin/sh
# Set to email address to send to
EMAILADDR=$1
# Set WARNING percentage
ALERT=60
# Set CRITICAL percentage
CRITALERT=90
# List the filesystems and put in $output.
df -H | grep -vE \'^Filesystem|tmpfs|cdrom\' | awk \'{ print $5 \" \" $1 }\' | while read output;
do
# Get the percentage from the output.
usep=$(echo $output | awk \'{ print $1}\' | cut -d\'%\' -f1 )
# Get the partition
partition=$(echo $output | awk \'{ print $2 }\' )
# Compare with CRITALERT since it\'s higher value
if [ $usep -ge $CRITALERT ]; then
# echo the body to the mail program (-s is subject) and SEND
echo \"Running out of space \\\"$partition ($usep%)\\\" on $(hostname) as on $(date)\" |
mail -s \"Critical Warning: Warning: $partition is at $usep% of capacity\" $EMAILADDR
# If it\'s not above critical, test to see if it\'s above ALERT.
elif [ $usep -ge $ALERT ]; then
echo \"Running out of space \\\"$partition ($usep%)\\\" on $(hostname) as on $(date)\" |
mail -s \"Warning: $partition is at $usep% of capacity\" $EMAILADDR
fi
done


