讲解Linux Shell、辅导Java/C++语言、讲解myscript、CS/python编程辅导
- 首页 >> Python编程Linux Shell Scripting II
Procedure
Create a script file for the purpose of user and group management in Linux. Assume that
the script is run with elevated permissions.
1. Create a script file called myscript.sh using vim or vi.
2. The first line of the script file must force the use of the bash shell.
3. At the beginning of the script file there must be a section of comments that contain
the following items:
assignment number
student name and student number
course and lab section number
name of the script file
the submission date
a description of what the script file does
4. Your script file must be properly commented.
5. It must contain a menu that gives the user a choice of five items labeled A - F and
Q, and a prompt asking for what the user’s choice is. Use the following labels for the
menu.
Create a user account
Delete a user account
Change supplementary group for a user account
Change initial group for a user account
Change default login shell for a user account
Change account expiration date for a user account
Quit
6. This script file must loop using a while loop. When it runs, choose one menu item.
A message must be displayed if an invalid option is chosen.
7. The menu choice must be decoded using an if-elif-else structure.
8. The if structure must accept upper or lower case letters. Use || operator to allow
upper or lower case characters.
If A or a is chosen, the script must prompt to enter the following information:
Username
User’s home directory
Default login shell
Create the user account based on the information given above
If B or b is chosen, it must prompt for username of the account to be deleted, and
delete the user account as well as the user’s home directory
If C or c is chosen, it must prompt for username and group name that is added as a
supplementary group for the user account
If D or d is chosen, it must prompt for username and group name that is used as
the initial group for the user account, and change the initial group for the user
account.
If E or e is chosen, it must prompt for the username and shell name, and change
the default shell for the user account.
If F or f is chosen, it must prompt for username and expiration date, and change
the expiration date for the user account.
If Q or q is chosen the script must end.
9. The script should sleep for 3 seconds after each menu item is selected, before the loop
causes the menu to be redisplayed
10. Below is a sample of a while loop:
choice=n #initialize to dummy value
while [ "$choice" != "Q" ] && [ "$choice" != "q" ]
do
clear
echo -e "Choice:\c"
read choice
echo "You Entered $choice"
sleep 3
done