Exercise 4 on lab 8 done
This commit is contained in:
parent
78e47a91e3
commit
26b68d4456
54
Labb8/ovning4.sh
Executable file
54
Labb8/ovning4.sh
Executable file
@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Jack-Benny Persson
|
||||
# LX13
|
||||
# Exercise 4 on lab 8 (Write a script that sends a report to the sysadmin
|
||||
# about the 5 biggest homefolders on the system
|
||||
|
||||
# Binaries
|
||||
Sed="/bin/sed"
|
||||
Awk="/usr/bin/awk"
|
||||
Du="/usr/bin/du"
|
||||
Mktemp="/bin/mktemp"
|
||||
Mail="/usr/bin/mail"
|
||||
Printf="/usr/bin/printf"
|
||||
Rm="/bin/rm"
|
||||
|
||||
# Variables
|
||||
Admin="jake"
|
||||
|
||||
# Sanity checks
|
||||
for Bin in $Sed $Awk $Du $Mktemp $Mail $Printf $Rm; do
|
||||
if [ ! -x $Bin ]; then
|
||||
echo "Can't execute $Bin"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -w /tmp/ ]; then
|
||||
echo "Can't create temporary files, aborting"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Main
|
||||
|
||||
# Create a temporary file
|
||||
File=`$Mktemp -t homeusage.XXXXXX`
|
||||
|
||||
# Redirect all output to the temporary file
|
||||
exec 1> $File
|
||||
|
||||
# Create the mail content
|
||||
$Printf "Home folder usage report (the top 5 users)\n\n"
|
||||
$Printf "Usage \tUser\n"
|
||||
$Printf "----- \t----\n"
|
||||
$Du -sm /home/* | sort -r | sed -n '1,5p' | awk '{ print $1 " Mbyte \t" $2 }'
|
||||
|
||||
# And finaly send it to it's recipient
|
||||
$Mail $Admin -s "User usage report" < $File
|
||||
|
||||
# Clean up
|
||||
$Rm $File
|
||||
|
||||
exit 0
|
Loading…
x
Reference in New Issue
Block a user