Operating System Assignment 1 Shell Programming
Prepared By: Yeo Boon Pu Page 1 of 1
Shell Programming Assignment
Assignment Objectives
The objectives of this assignment is to ensure that the students have understood the
following concepts:
· the UNIX commands, the file and directory manipulation commands, the
input/output redirection and piping in UNIX
· make use of the default screen editor, vi to create and modify files in UNIX
· to write shell scripts that achieves the sequence, the selection and the iteration
constructs.
Assignment Background
Write a menu-driven shell program to simulate a network management environment.
It provides the administrator the capabilities of locking the workstation, viewing the
current login users on the screen, creating a log file of the current login users,
changing the user password and logging out of the system.
In order to facilitate the login process, you need to define a password file with the
structure as follows: user name | password (you will need to create the password file
with at least 5 records)
Functional Specifications
The entire system is made up of 2 major components, namely the login shell and the
system main menu. Each of these components should be implemented in different
files. Also for each of the sub tasks listed in the main menu can be handled by a
separate script. This would mean that total SIX files would be needed for the final
application. On top of these six files, you need to create a simple password file as
stated in the above assignment background.
Alternatively, you could use separate functions within a single file to perform the subtasks.
However if you choose this approach, there is a word of advice: try to
implement the system within a reasonable file size. Otherwise the control structures
would very difficult to handle when they are combined into one large file; you will
save time and effort by breaking the tasks into pieces. Each of the sub tasks is also
marked with stars to indicate the relative difficulty.
Make sure that a failed commands, or any other internal error, does not print some
kind of technical error message, or worse, no message at all. If, for example the user
is not found in the password file, a simple "user not found" error message should be
issued.
Operating System Assignment 1 Shell Programming
Prepared By: Yeo Boon Pu Page 2 of 2
Program Operation (**)
As the system starts up, the user will enter have to enter the user name and the
password. The program should check:
· whether the user account has existed in the password
· whether the user has entered the correct password
If either of these conditions is not met, an error should be produced, and the login
prompt should be displayed again for the user to login. You have to ensure that the
password is not seen during its entry.
Main Menu (*)
If the user has entered a valid user name and password, the main menu should be
displayed. It will look something like the following, but you should use your own
artistic sense to format it more carefully. You might use letters instead of numbers as
the menu choices, for example.
Main Menu:
1. Lock the workstation
2. Check current online users
3. Write current online users to file
4. Change password
5. Logout
6. Quit
Choice:
Choosing 6 for "Quit" will terminate the program. All other options produce the
following requirements as described below.
Lock the Workstation (***)
Upon selecting this option, the terminal will be locked. In order to unlock the
workstation, the user has to key in the login password that he/she has used during the
login process.
The workstation is locked. Enter the password to unlock the station
Password:
Also note that the password should not be displayed when the user keys in the
password to unlock the workstation.
Operating System Assignment 1 Shell Programming
Prepared By: Yeo Boon Pu Page 3 of 3
Check Current Online Users (**)
Upon selecting this choice, the program will print a list of current active users in the
network and along with it, the total number of login users as follows:
=========================================================
Printing current login users
=========================================================
root console Aug 8 09:47 (:0)
yeobp pts/1 Aug 11 13:14 (172.17.11.199)
root pts/7 Aug 8 09:47 (:0.0)
root pts/8 Aug 8 09:47 (:0.0)
root pts/9 Aug 8 09:47 (:0.0)
root pts/10 Aug 8 09:47 (:0.0)
=========================================================
Total number of log in users are: 6
=========================================================
Press ENTER to continue
Write Current Online Users to File (**)
The program should prompt the user the name of the file that he/she would like to
store the log information into. Upon obtaining the file name, the program will then
print the current login users details together with the total number of login users to the
specified file.
If the file does not exist, the program should be able to create it and if the file exists,
then the file will be overwritten.
Change Password (***)
Upon selecting this choice, the user will be prompted to enter the user name. If the
user name does not exist, an error message will be displayed.
If the user name is found in the list, then the program will prompt the user to enter the
password and confirm the password by entering it the second time. If the password
does not match, then the change of password procedure is not successful. The old
password of the user should be retained.
However if the password is correctly entered twice, then the program will update the
password with the new password. Thus the next time when user enters the system, the
user has to use new password to login.
Logout (**)
When the user has selected this choice, the program will log out the user and it should
display the login prompt so that the next user could log into the system.
Operating System Assignment 1 Shell Programming
Prepared By: Yeo Boon Pu Page 4 of 4
Hint:
The method for deleting a record in a file is described as follows: Use grep to output
all of the lines of the file except for the one to be deleted. Put this output into a
temporary file, and then replace the real data file with the temporary. The data file
will now contain all the lines except the deleted one. Then add into the file the
existing user name and the new password.
If you were want to know more about a specific command, enter man at
the prompt and the system will display a useful description of the specific command.