IT 3110: Systems Automation
Shell Scripting 5
This assignment will hone your skills as a Bash shell programmer.
Write a script that will do the following (each of the following should be placed in a seprate function):
- present a menu to the user:
- If the user selects option 1, your script should randomly display a quote from this page. (See hints at bottom of page)
- if the user selects option 2, your script should prompt the user for integers until they enter
Control+d. Then it will sum up the integers and display the total to the user.
- if the user selects option 3 your system will display the users that have been logged in for a day or more on
- Option 4 will quit the script
- Any other option will display an error message to the user and redisplay the menu.
This can be passed off in class, or Take a print screen of your scripts running. Also upload your scripts.
- Submit your report and images to the
SCRIPT 5assignment in the Canvas
To get a random quote, here is one possible strategy:
- download the file using wget or curl
- figure out how many times
%occurs in the file, maybe grep and wc magic
- get a random number between 1 and the number of
r=$((1 + RANDOM % $num))
- loop through the file and count each line, and count each time you find a percent. When your linecount is equal to the random number above, store that in a variable (start). When your percent count is equal to the random + 1, store that in another variable (end).
- Maybe use sed to print out the lines between start and end.
Last Updated 12/22/2020