Out: Feb 11Th, 2015 Due: March 4Th, Beginning of Lecture (8 Am) 40 Available Marks/Marked

Out: Feb 11Th, 2015 Due: March 4Th, Beginning of Lecture (8 Am) 40 Available Marks/Marked

Out: Feb 11th, 2015
Due: March 4th, Beginning of Lecture (8 am)
40 available marks/marked out of 35. Marks above 35 will be applied as a % to your assignment mark only.

TECH 154 – Lab 4

Part I: Using Unix utilities to extract information from commands and data files.
We use the following commands to extract information from data files and commands. Record all commands used. In cases where you are unsuccessful in producing the desired effect described what you tried and the nature of the error for part marks.

  1. head, tail, tac and sed (10 marks)
    In a.-d. use head, tail and tac. In e.-h. use sed and tac. Use cat –n at the beginning of the pipeline to verify the line numbers.
  2. Extract the last 5 lines of the file /etc/passwd (1/2 mark)
  3. Extract the first 3 lines output from the who command (1/2 mark)
  4. Extract lines 200 to 206 of the file /usr/share/X11/rgb.txt. (1)
  5. The last command produces a record of every login since the log file /var/wtmp was last rolled over. Every time someone logs in newer entries are added at the beginning (for 2 marks... Note – this may seem hard at first. If you don’t get this in 2-5 minutes, put it aside and get back to it later.)
  6. Extract the last 4 lines containing data from the last command, that is, your use of head, tail and tac should exclude the blank line and the phrase wtmp begins Fri Jan 2 12:45:13, but include the login times for king, ndrj0059 (2x) and cxmc0015. (Hint: If you display the file first in reverse order, the last 6 lines become the 1st 6 lines.)
  7. Extract the 1st 3 lines output from last.
  8. Create a 1 line command sequence that displays the output of i and ii so that the logins are displayed from earliest to latest.
  9. - h. Repeat parts a-d using the sed command. You can use tac but not head or tail.
  10. In class we discussed how one could live without the tail command as the following sequence works just as well to give us the last 5 lines:
    cat –n file | tac | head -n 5 | tac
    Come up with a sequence that gives us the last 12 characters of of a file without using tail. (2 marks)
  11. cut, paste, tr, expand (8 marks/2 each)
  12. The command man asci produces lookup tables for ASCII characters. Towards the end of the output it shows compact tables in hex and decimal. Use wc to determine the number of lines output.
    Use head, tail and cut to extract only the hex table.
  13. The command ps aux lists all processes currently running on the system. Extract just the USER, %MEM and COMMAND fields using cut’s -c flag.
  14. The file /etc/passwd lists all users on the system. The fields are delimited by colons. You can look up the meaning of each field by typing in the command man 5 passwd.
    Extract the GECOS field (real name) and the account. Display them in reverse order, real name first, separated with a # symbol. You may use temporary files.
  15. Examine the file /usr/share/zoneinfo/zone.tab. You’ll note that it uses tabs to separate the 4 fields. Read over the man page for cut very carefully on how to handle the tabs – it’s less difficult than you think! Extract the first 3 fields separately then paste them together using a semicolon as a delimiter.

Part II: HTML – Lists and Tables (16 marks)

Create an HTML web pageLab4.html in your public_html directory that contains the following:

  1. A definition list (tags: DL, DD and DT) based on your notes for this course that define 4 distinct terms, two relating to Unix and two related to HTML. (4 marks)
  2. An ordered list of 4-6 things (tags: ol, li) that you need to do over then next few weeks, with one of those items broken out into a sublist of at least 3 more items. Use 2 different list styles (roman numerals, alphabetic , hebrew, greek or armenian), starting a some value other than 1. (4 marks)
  3. Repeat the above using an unordered list (tags: UL, LI). (2 marks + 2 bonus marks if you use small images as bullets for your list.)
  4. A table of with a heading that describes 4 actual Unix commands and related flags covered in (tags: TABLE, TR, TD, TH) The table should have a heading and look something like this: (4 marks)

Cmd Name / Flags / Purpose
gcc / -c -o -s / Compiles a C program. –s generates an assembly language listing. –o is followed by the name of the executable (output) of the command. –c means compile to object code but not to link in libraries.
Usage: gcc hello.c -o hello.exe
...
  1. Add a heading (tag: H1 or H2) to each of you answers. Create a set of internal hypertext links to each sectio and place these at the top and bottom of your web page. (2)

Part III: The date command (6 marks)

  1. What is the difference in output between the following versions of the date command:
    date
    date –u
  2. Issue the following commands and record the results:
    export TZ=Turkey
    date
    export TZ=Canada/Newfoundland
    date
    To restore the date to Toronto time,
    export TZ=Canada/Eastern
  3. Refer to the directory /usr/share/zoneinfo To reset the current timezone issue the command:
    export TZ=filename
    where filename is the name of a file within this directory. If the timezone file is in one of the subdirectories you need to use the file name relative to the zoneinfo directory: ie: TZ=Canada/Yukon. Search through the directories and set TZ to the timezone for Maputo which is the capital of Mozambique. Note the time (and date) for the time here in Toronto and for the time and date in Maputo.
  4. Issue the following command: date +"%A, day %u of ‘%y, %Z"
    and record the result.
    Refer to theman pages for the date command. Describe the effect of each format codes used.
  5. What is the command to produce a date with the following (sample) format:
    Its Tuesday, the 24th day of September, and 18 minutes past the 9th hour

you should use 5 different format codes.

  1. Put your birth date and the date you expect to graduate in a file. Use the date -f flag load the dates from the file and display both as the number of seconds since the epoch and in the form YYYY/MM/DD with leading zeroes for month and day.
    In your report show the original data file, the command used and the output of your command.