slotegraafd
New Member
Hi,
So I'm working on editing this code and I thought I had all the errors for it fixed but when I run the code it works, like the code shows up but when i type in the letter to make a selection it doesn't actually execute the right part of the code it doesn't do anything and I'm not sure how to fix it.
This is my full code and the selections I'm having problems with are [Dd]) and [Ee])
So I'm working on editing this code and I thought I had all the errors for it fixed but when I run the code it works, like the code shows up but when i type in the letter to make a selection it doesn't actually execute the right part of the code it doesn't do anything and I'm not sure how to fix it.
Code:
while true
do
#Clear the screen before displaying the menu again
clear
echo " SYSA 3204 - Main Menu "
echo "---------------------------------"
echo "U. User Analysis"
echo "D. Disk Usage "
echo "E. Exit from the menu"
#read the option
read -p "Enter Your Selection (U/D/E) : " option
case $option in
[Uu])
# validate lastname to contain lowercase characters - 5 to 8 characters
while true
do
read -p "Enter the directory name : " dname
echo $dname | grep -qE '^[A-Z]*$'
if ([ ?? -eq 0 ]); then
if ([ -z "$dname" ]); then
echo "Directory Name cannot be empty"
else
length=$(echo $dname || wc -c)
if [ $length -ge 6 ] || [ $length -le 9 ]; then
break
else
echo "Directory Name must be between 5 to 8 characters"
end
fi
fi
else
echo "$dname is invalid name - you must enter lowercase characters between 5 to 8"
fi
done
if [ ! -d $dname ]; then
mkdir $dname
fi
if ([ ! -f $dname/users.txt ]); then
touch $dname\users.txt
fi
last | grep -e ^dm | grep "Dec 6" | awk '{print $1" "$5" "$4" "$2}' >>$dname/users.txt
no_users=$(cat $dname/users.txt | wc -c)
if ([ $no_users -gt 5 ]); then
awk
'BEGIN {FS=":" ; \
printf "%-15s %-10s %-20s %-20s \n----------------------------------------------------------\n"
"Login Name", "Terminal", "IP Address", "Time Spent}
{printf "%-15s %-10s %-20s %-20s\n" $1, $3, $2,$4}
END {print "----------------------------------------------------------"}'
$dname/users.txt
echo "Number of Users : no_users"
else
echo "Number of Users less than 5"
fi
;;
[Dd])
df | grep ^/ | awk '{print $3" "$2" "$1" "$5}' || tee data.txt
nos= cat data.txt | wc -l
echo -e "/nThe number of file systems = $nos on $(date +"%b-%Y-%a")\n"
echo "The highest File System is : "
(cat data.txt | sort -nk3 -r | tail -1)
;;
[Ee]) echo "Now I can relax- no more tests except Project 2 to finish"
esac
echo "Your Selection is wrong. Please enter A, D or E only"
done
read -p "Press Enter To Continue..." dummy
end
This is my full code and the selections I'm having problems with are [Dd]) and [Ee])