【求助】一份国外的shell作业,请大家来切磋
fly389
|
1#
fly389 发表于 2005-03-10 13:28
【求助】一份国外的shell作业,请大家来切磋
Dominion Consulting in Sydney needs a program to maintain its employee records file, which contains the following information about each employee: telephone number, name, department number, job title, and date of hire. This program should let users add, delete, locate, and display specific employee information. You can meet these needs by creating several UNIX shell scripts.
You start with creating a text file named records containing the following records with fields delimited by colons: 02-95671660:Jones:Sarah:B:45:sales manager:14-12-1995 02-93272658:Smith:John:C:43:technical manager:12-10-1993 02-98781987:Williams:Nick:T:35:computer officer:10-08-1998 02-99893878:Brown:Sarah:B:12:electrician:09-02-1992 02-95673456:Couchavid:A:26:chef:23-04-1994 02-95437869:Anderson:Sarah:K:19:CEO:21-09-1988 You main shell script (must be named menu) will present a menu of operations that a user may choose from. Among other tasks, these operations automate the process of 1. Displaying all current employee records on the screen. 2. Displaying all current employee records (formatted and sorted) on the screen. 3. Displaying only names and phone numbers on the screen. 4. Displaying only names and phone numbers (formatted and sorted) on the screen. 5. Searching for and displaying specific employee record(s). 6. Add new records to the records file. 7. Delete records from the records file. You could use some simpler combination of some UNIX commands to perform tasks 1, 2, 3, 4, and 5. For tasks 6 and 7, you need to write separate shell scripts (must be named add and delete, respectively), and call these scripts in your main script menu. You may need to investigate some or all of these UNIX commands: awk, sort, tr, cut, paste, sed, grep. You may also need to investigate some other UNIX commands. You are strongly recommended to make a directory named kxc254ass1 under your home directory, and use kxc254ass1 as your working directory for this assignment. Your Main Script menu Your main script menu will produce the following menu of operations that a user may choose from Employees Info Main Menu ======================== 1 - Print All Current Records 2 ? Print All Current Records (formatted) 3 ? Print Names and Phone Numbers 4 ? Print Names and Phone Numbers (formatted) 5 - Search for specific Record(s) 6 - Add New Records 7 ? Delete Records Q - Quit Your Selection: (waiting for user input) ? After the user makes a selection and that the selected operation has been completed, the above main menu must be displayed again so that the user can make another selection. You must use a while loop together with a case conditional to implement this. Additionally your script menu must clear the user screen before the main menu is displayed. In all of the following steps, every time the main menu is displayed the user screen has to be cleared first. ? At the beginning of your menu script, you must define three variables which take the values of records, add, and delete, respectively, and use these variables in all statements that refer to the files records, add, and delete. For example, you may define: record_file=records and use $record_file in all statements that refer to the file records. One advantage of such practice is that, if at a later time you have to rename the file records, or if it becomes necessary to get your shell script to operate on a different records file, you only need to modify the above one statement instead of modifying all statements that refer to the records file. Define the other two variables like these: add_file=add delete_file=delete ? Following the above definitions, your menu script must check to see whether the required files (records, add, and delete) actually exist under the current directory. If any of the files does not exist, your script menu must display the following message and then exit: Required file theMissingFile does not exist. For example, if records file does not exist, display “Required file records does not exist.”, and then exit. |