~ UCSB CS32 Summer 2013 — Programming Assignment 1 ~
Shell scripting. Brushing up C/C++
Released: August 7
Due on: August 15, 11:59pm

For this programming assignment, you will build an index of CS Department's students having personal web-pages. You will write a Bash script that retrieves information about students from CSIL and a C++ program that will accept this information and generate an HTML page listing student names and links to their web-pages.

To complete this assignment, you need to have a College of Engineering account in order to access the CSIL's server at csil.cs.ucsb.edu.

  1. get_users.sh

    First, you need to write a bash script that retrieves information from csil.cs.ucsb.edu about those students who have personal web-pages. Write this script as if you are working locally at csil.cs.ucsb.edu. For one thing, you can actually run your script on this machine. Alternatively, and more likely, you will run this script remotely.

    CS students' home directories are stored in /cs/student/. The name of each home directory is exactly the username of the corresponding student. Thus, simply listing all the directories under /cs/student/ can provide us with the list of usernames.

    We are, however, interested in only those students who have publicly accessible personal web-pages. We will assume that if there exists a readable file /cs/student/{username}/public_html/index.html, then student {username} has an accessible personal web-page and, hence, should be listed.

    But this is still not all. In addition, for each username we want to retrieve the full name of the corresponding student (for example, for username jhendrix the full name may be James M. Hendrix). Your script can obtain this information using finger. For example, executing

    	finger victor
    

    will print out some information about the user with username victor to standard output:

    	Login: victor         			Name: Viktor Amelkin
    	Directory: /cs/student/victor   Shell: /bin/bash
    	No mail.
    	No Plan.
    

    We are particularly interested in the field Name, whose value can be extracted from finger's output, for example, using sed or even something as simple as cut.

    There is one problem, however, with retrieving usernames based on the names of directories under /cs/student/. There are sub-directories there, such as cs32, that do not correspond to any "true" user, yet they may contain ./public_html/index.html. If you try to finger one of such "fake" users, then finger will respond

    	finger: {fake user name}: no such user.
    

    Make sure that your script does not include such fake users on the list; include only those users whose full name can be acquired with finger. (We hope that nobody fills out finger information for fake users, like it is done here finger coke@cs.cmu.edu.)

    Now, you know everything to retrieve the list of users. What remains is just to format the output properly. Here is the specification for your script:

    	File Name: get_users.sh
    
    	Input: [no input]
    
    	Output: multiple lines, each of the form "username | Full Name\n".
    		These lines are written to the standard output.
    
    	Example output:
    
    		adoe | Alice Doe
    		bjohnson | Bob Johnson
    		larry44 | Larry Ellison
    
    	Running the script:
    
    		* locally on csil.cs.ucsb.edu: ./get_users.sh
    
    		* remotely: ssh {your_login}@csil.cs.ucsb.edu 'bash -s' < get_users.sh
    
  2. build_index.cpp

    When get_users.sh script is ready, you can move to the second part of the assignment, namely, to writing a C/C++ program that reads the output of your script and generates an HTML page listing students and the links to their web-pages.

    This part is easier than it seems. You are given a template for the final HTML page — page_template.html. This template is almost the complete HTML page, and you just need to fill a few gaps in it.

    The template contains two placeholders — {authors} and {rows}. Your program will replace {authors} with the names of the students on your team, and {rows} with the list of students and the links to their web-pages. Rows are put one after another; the format for a single row is given as another template -- row_template.html. This template also contains two placeholders -- {name} and {user_name} (notice that {user_name} occurs and, hence, must be replaced twice in the row template). {name} stands for the full name and {user_name} stands for the username of a particular student.

    The specification for your C++ program is as follows:

    	File Name: build_index.cpp
    
    	Compiled with: g++ -Wall -O3 build_index.cpp -o build_index
                       (or just use the provided Makefile)
    
    	Input: the output of get_users.sh through the standard input
    		   (of course, you can type an appropriate input to this
    		   program without using the script; if you are doing so,
    		   do not forget to press Ctrl+D at the end to signal the
    		   end of input).
    
    	Output: the program prints the number of discovered students
    		to the standard output (e.g., "Number of students is 99.")
    		The program also generates the HTML page. The generated
    		page should be  written to file www_index.html in the same
    		directory as the program. For an example of the final
    		www_index.html, look at www_index_example.html (your list
    		of students will be larger). If you fancy, you can change
    		the page's template, but make sure that the page displays
    		your names (as the authors) and the list of students and
    		their web-pages.
    
  3. Building the web-page index

    Finally, you have everything to build a web-page index. You can chain your script and the program as follows (I am running this command on my machine, so I need to ssh to CSIL):

    	ssh {your_login}@csil.cs.ucsb.edu 'bash -s' < get_users.sh | ./build_index
    

    You can modify and use build_index.sh script to automatically recompile build_index.cpp and run both the script and the program.

    As a result, you should obtain the HTML page www_index.html. To make sure it is generated correctly, try to open it in your web-browser.

  4. Submitting your work

    Turn in the following files:

    	get_users.sh -- your user-info-retrieving script
    	build_index.cpp -- your index-building program
    	www_index.html -- your generated web-page index
    

    ATTENTION: get_users.sh and build_index.cpp must contain a header with your name(s) in the comments. If you omit your name(s), you can lose your grade for this assignment.

    To turn your code in, log in to csil.cs.ucsb.edu, run

    	turnin pa1@cs32 {list of your files or a directory containing them}
    

    and follow instructions. You can submit your work multiple times. Please, respect the deadline.

    If you have any problems with logging in to csil.cs.ucsb.edu or any other questions regarding this assignment, please let me know.

Victor Amelkin