COMP1125 Assignment
{`UNIVERSITY OF THE WEST INDIES Department of Computer Science, Mathematics and Physics Course: COMP1125 `}
1. What are the commands to accomplish the following: [24 marks] (other than stated, 2 mks each)
- The total number of users currently logged onto the system
- Create a sorted list of all users of the system and save to a file name userSYS
- Using the commands, cal, sed and tr and the pipe “|” display the numerical days (eg, 1, 2, 3, etc) only of the month of October, with each day on a separate line. (3)
- Display the names of the printers on the system.
- Set your default printer to printer2
- A file contains 54 files of information. Using the head and tail commands only, display the 46th and 47th lines only. (3)
- Display, in three columns, a list of all users of the system.
- Create the command ‘rm –i’ with the nickname “r”.
- Use the find command to recursively display the names of all the files in your home directory, ignoring the names of the files in the funxdir
- Use the find command to recursively display all the files in your home directory with a file permission of 644.
- Using the date and cut commands only, display, only, the current month and the current day of the month.
2. Use one of the editors, ed, edit, ex or vi to edit the file in this question. Note that your answers to this question do not necessary have to be related to the editor that you have elected to use, any other UNIX command would suffice. [12 marks]
- Copy the file, ASSIGN from the /tmp directory into your current directory and name it ASSIGN???? (2)
- For each line that contains the pattern seminar, change only the first occurrence on that line, to the pattern SEMINAR????. Save the changes. (2)
- Using the cat and grep commands only, display those lines, along with the line number, where the word computer is found. (2)
- Assume that the number of lines in the file is unknown. Excluding the last four lines, with a single command, replace every occurrence of the patterns subject and Subject with the pattern COURSE????. Save the changes. (3)
- sing a single command, create a file call ????TEACH, which is similar to ASSIGN????. The only difference is that for every line that contains the word COURSE????, the file ????TEACH has a line above which reads: TEACHING IS A 24 HOUR JOB (3)
3. Copy the file Partyfile from the /tmp directory to your current directory. The information in the file is in the format: Name, Phone Number, and the money contributions to the ABC party for the past four months. Use this file to answer the following questions. [9 marks]
- Print the first names only of those persons whose contribution was more than $250, but not more than $800 in the fourth month. (2)
- Print the name and phone numbers of those who contribution in the fourth month is a factor of 5 (2)
- Display the entire file, showing six stars (******) at the end of a line, if the first month’s contribution is $250. (2) d) For each line, display the area code and surname (in that order). (3)
4. State the commands in a, b and c. Create a script for d. [18 marks]
- Assume that your home directory contains only files. Use the ls and nawk commands to sum the files sizes in your home directory, only if the file name contains a vowel (lowercase). (5)
- Use who, nawk, sort and uniq to display a sorted list of active users.(4)
- List all the processes that are currently running which are owned by ‘root’; substituting ‘root’ with your username. (4)
- Write a nawk script that prints out all lines in a file, except the blank lines. It displays the total number of blank lines. It also displays the total number of fields in the file, excluding the first and last fields of each line. (5)
5. Copy the file addrfile from the /tmp to your current directory. The format of this file is as follows: Name, Telephone Number, Address, Date of Birth and Salary. [12 marks]
- Using the sed command, display this file with all the lines, except those lines containing Chestney (3)
- Print all the lines where a birthday falls in December. (Format: dd/mm/yy) (2)
- Below each line which contains the word Chelsea, change the word Bridgetown to all capitals (BRIDGETOWN). (3)
- Display the name and the address if the area code of the telephone number is 548. (2)
- Display the file with the words COLLECT CUSTOMER PRIZE above the lines where Joseph is found. (2)
6. For this question typed your answers in the SOLUTIONS???? file. [19 marks]
- Explain the role of the /etc/passwd Give the name and function of each field found in this file. (4 + 2)
- Explain the role of the /etc/shadow Give the name and function of each field found in this file. ( 2 + 3) c) Which file in the /etc directory is responsible for starting the services of FTP, telnet and the like (2)
- Which file in the /etc directory is responsible for which processes are started at bootup or at the different runlevels. (2)
- Which file in the /etc directory is responsible for determining which port the FTP, telnet and so on are given. (2) f) In which file is your password stored. (2)
7. Copy datafile4 to your home directory from /tmp. [20 marks]
- sort datafile4 by last name and save to the file sort????. (3)
- sort datafile4 in reverse order by first name and save to the file SORTrev????. (4)
- Write a command that would extract the largest value from column 5 in datafile4. (Hint use the pipe “|” to assist you). (5)
- Create a nawk script called west???? which counts the number of lines where the pattern western or Western is found in datafile4. It also, for all scores in the last column that are at least 18, prints the entire record and finds the average of those scores. (8)
- Create a crontab job that will:
- Move all the files in your home directory where the name contains the letter k to your funxdir directory, every Thursday well as the 12th day of April and September at 11:30 AM. (3)
- Create a tar file called files that backs up all the files in your home directory where the name ends with a uppercase letter, on the 2nd and 6th days of the last three months of the year at 4:15 & 4:25 PM (3)
8. [26 marks]
- Create script called Copyfiles, which does the following. The user is asked to enter a filename: “Enter the file name”. Only if the filename entered is a valid filename, the script should precede. The file contains a list of filenames which currently exists in your current directory. For the list of file names found in the file, make a backup copy, in the current directory (with a “.bkup” extension) those files that have read and write permissions. Of those files that were copied, display their name and the first word found on the last line of each file. If the file entered is invalid display “Invalid <filename>” (6)
- Write a script called, Prime????, which accepts a number which must be less than 1000 and displays the largest prime number that is less than twice the number entered. (8)
- Write a script called TheTimE????, which displays the actual information from the system in the following manner:
The day of the week is Wednesday.
The system was last rebooted on Sep 26 at 14:35 and has been running for 5 day(s), 2 hrs and 25 minutes. (6) - Create a script called Capital????, which asks the user, “ What is the capital of Angola?”. If Luanda is entered, a message “YOU ARE CORRECT” is displayed. If the answer is incorrect, display the message “INCORRECT, THE CAPITAL OF ANGOLA IS”. The script exits only when the correct answer is entered!! (6)
9. Create a script called UPdata???? that will: [9 marks]
- Add an 8th column ( 2 times (7th column * 6th column) ) to datafile and save to data????. (3)
- Displays only those records in data???? if the value in the last column ends with a 4 or 0. (3)
- Tell the user the number of records in dataf???? where the sum of the last two columns is more than 90 but less than 130. (3)
10. Write a script called Concat???? that will: [12 marks]
- Take four command line arguments, the first two are files and the third argument is a pattern (eg “Male”) and the fourth argument is also a pattern (eg. “Female”).
- Assume the first file exists, however ensure that the second file does not exist – the second file is to be created in the script. If four arguments are not received, inform the user that he/she must enter four arguments.
- If the first file is less than 100 lines long, display the message “<file> length is too short” and exit the script. If it is 100 lines or more, do the following: For the first 50 lines, only if the first pattern (third argument) is found: Replace the third pattern with the fourth pattern, extract only those lines and save those lines to the second file. For all the other lines in the file, only if the second pattern is found, extract only those lines which does not contain the second pattern (fourth argument), place four stars (****) at the end of those lines that starts with an a, B, S, s or T and append all lines extracted to the second file. Display appropriate messages if the pattern is not found.
- Displays only the line numbers of the blank lines in the second file.
11. Write a script called CHKuserID???? that will: [10 marks]
- Take as a command line argument, a user’s login name.
- Test to see if the command line argument was provided, and provides an adequate message if one was not provided.
- Check to see if the user is a valid user of the system. If so, print “<user> WAS FOUND” and prints in the following order, the user’s home directory, the shell that they use, their userid and groupid. Additionally, if the user is “root” then for those group names of the system which contains the letter ‘o’ display the number of them, and their names. If the user is not found, print “No such user on oursystem”.