My homework asked me to
- The users are storing way too many files in their home directory and you would like to notify the top 5 offenders. You might want to run this script again for more or less users so this selection will prompt for the number of users to identify, check how many files they have in their home directory and send a list of those users to the standard output.
This is what I have for the first parts so far; I just cannot figure out #5.
echo " Please enter file name: "
read workingfile
while true
do
echo "1) Check who is logged into the system and pull up contact information"
echo "2) Check who has left a system process running and stop it"
echo "3) Check if two users have the same userid, and prompt to change it"
echo "4) Get a list of all users on file and list information about them"
echo "5) List the top 5 users that have to many files in their home directory and list them"
echo " "
echo -n "Choice: "
read choice
case "$choice" in
1)
user=$(who | cut -d' ' -f1 | sort | uniq)
grep "$user" $workingfile | sed 's/\:/ /g' | sed 's/stu[0-9]*//g'
break
;;
2)
echo "Please enter a username: "
read user
echo $user
ps -u $user
echo "Would you like to end the proccess for $user ? (yes or no)"
read choice2
if [ $choice2 = "yes" ];
echo "killall -u USERNAME.” break
else
echo "We will not be stopping any background proccesses!"
break
exit
fi
;;
3)
sed -i '0,/stu5/{s/stu5/stu6/}' myuser.txt
sed -i '0,/stu5/{s/stu5/stu4/}' myuser.txt
echo "Testing if a user has the same id"
if [[ $(grep -o "stu[0-9]" $workingfile | uniq -d) != 0 ]]; then
result=$(grep -o "stu[0-9]" $workingfile | uniq -d)
echo " We will be replacing the first instance of $result please input what number you'd like to replace it with!: "
read input
echo "replacing id..."
sed -i '0,/stu5/{s/stu5/stu4/}' $workingfile
cat $workingfile
break
else
echo " There is no result!"
break
exit
fi
;;
4) echo "List of all users in file: "
cat $workingfile | sed 's/\:/ /g' | sed 's/stu[0-9]*//g'
break
;;