Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a shell script that displays the following menu items, prompt the user

ID: 3902434 • Letter: 1

Question

1. Write a shell script that displays the following menu items, prompt the user to enter a selection, and then executes the command associated with that menu item. If required, prompt the user for additional commands should the menu item require it.

The menu items:

(a) Display a list of files and directories in the current directory

(b) Display a long list of the contents of the current directory

(c) Display a list of the last n messages in /var/log/messages, prompting for the value of n

(d) Display the contents of this script

(e) Display the contents of this script in reverse

(f) Exit the script Don’t forget to have the script keep running until the user selects the exit option.

Linux keeps track of all log-in attempts in the file var/log/auth.log. Write a shell script that searches the contents of this file and displays any entries where a user logged onto the system as the administrative user (that user will have user name of root and a uid of 0).

Explanation / Answer

Answer 1--->Here is your code

clear

e="y"
while [ "$e" = "y" ]
do

echo "(a) Display a list of files and directories in the current directory"

echo "(b) Display a long list of the contents of the current directory"

echo "(c) Display a list of the last n messages in /var/log/messages"

echo "(d) Display the contents of this script"

echo "(e) Display the contents of this script in reverse"

echo "(f) Exit the script"
echo "Enter your choice"
read ans

if [ "$ans" = "a" ]
then
ls
fi

if [ "$ans" = "b" ]
then
ls -l
fi

if [ "$ans" = "c" ]
then
echo "Enter the number of lines to display from /var/log/messages"
read n
tail -$n /var/log/messages
fi

if [ "$ans" = "d" ]
then
cat a1.sh
fi

if [ "$ans" = "e" ]
then
#tac is the command to display the reverse contents of a file
tac a1.sh
fi

if [ "$ans" = "f" ]
then
exit
fi
done

*****script name is a1.sh

Answer 2

Put into a shell script, use only this line i your script.
grep root var/log/auth.log