CS160B lab5-online Boyd

Lab 5 (online) 5 points

Note: Lab5 begins the implementation of a real program, which is continued in lab6. As a real program, there is more work and much more description. Start early. You must do lab5 to do lab6. There is extra credit available in lab6.

I have written about half of lab5 for you, as discussed in the Hints section. I suggest you start with that part and add the missing code.

In this assignment we will be running the system program chfn, and you will be invoking chfn from within your shell script. If your program hangs when running, make sure you abort it by typing control-C until you get a bash prompt back. If you get disconnected while chfn is running, it will lock the file up and noone else will be able to run chfn until the system administrator fixes it. If chfn refuses to run and gives you a message about being locked, send me a private email and I will ask the administrators to fix it.


In Lab 5 and Lab 6 we will be implementing a program to help the user use the "user information program" on the local system, called finger. finger was designed for central servers that have many users logged in. In the current climate of many small personal computers it has fallen into disuse. However, on a system like hills it can be useful. The syntax of finger is finger [-m] name. finger performs a pattern match using name on all system user logins and real name or titles (see below). (The  m is used if string is the user's login. This suppresses the pattern matching and speeds up finger)

Here is sample output from finger

bash$ finger -m gboyd

Login name: gboyd (messages off) In real life: Unix/Linux Instructor

Bldg: L413

Directory: /users/gboyd Shell: /usr/bin/bash

On since Oct 30 16:57:17 on pts/22 from dsl027-156-114.sfo.comcast.net

New mail received Wed Jun 13 09:54:04 2001;

unread since Sat Oct 30 16:57:17 2010

Project: Unix/Linux


To learn as much as I can about Unix and Linux

and hopefully teach some of it.

Alternate plan: Anything but Microsoft

finger's output includes information provided by the system such as the user's home directory, when they last read their system mail and when they last logged in. It also outputs some personal information provided by the user (which I have indicated above in bold). This includes

This part of the personal information is stored in the system passwd datafile. The user can update this information by running the program chfn (for change finger information)

Everyone used to know how to set up their finger information. Today, no one does. Your program will help them do it by 1) ensuring that their home directory is searchable (executable) and that their .plan and .project files exist and are readable, 2) asking them questions to retrieve their title and location, then, 3) running chfn for them to set their finger information.

The final version (in lab6) will be named pinfo. This first, partial, implementation (in lab5) will be named xpinfo.

xpinfo's job will be as follows:

name or title (retrieved from the user)
location (retrieved from the use

Again, you must write this last part, but I show you how in the Hints below.

As we have learned, your error messages and prompts must be output to standard error. (If you use the functions provided in the starting version of xpinfo, and the read -p command for your questions, this is done for you.) Here is sample output from a version of xpinfo. In this example, the user's home directory was searchable, his two files existed, but the .plan file had the incorrect permissions:

bash$ xpinfo

Welcome to xpinfo - Set your finger personal information

Your ~/.plan file must allow r access for all users.

Do you want me to change its permissions?(y/n):y

Enter your title:Linux Instructor

Enter your location:L413

Your finger information has been updated successfully!


This is a lot of work for a lab, so I have written part of it for you. The file xpinfo in the lab5-online directory in our public work area contains code to

It is also fully documented and contains and uses three functions to help you. (You are welcome to write the entire program by yourself, but xpinfo is about 70 lines of code. I suggest you start with the part I wrote for you and use the functions I wrote to help you when writing your part.)

Creating the file for chfn may confuse some of you. It is easy. Assuming $title is the title retrieved from the user and $location is the location they provided, here are two examples of code:


echo "$title" > $TMPFILE

echo "$location" >> $TMPFILE

echo -e "none\nnone" >> $TMPFILE

chfn < $TMPFILE

rm -f $TMPFILE

echo -e "$title\n$location\nnone\nnone" |


Note that I didn't throw away the output of chfn, which you must do.

If you submit an assignment on Insight that uses standard input redirection ( < ), web forms should be used for the result to be readable. If Insight messes up your formatting and you can't fix it by changing the submission method to web forms, go ahead and submit the copy on hills and send me a private message about it.

To submit

Submit a copy of your shell script online for grading by pasting it into the assignment submission box. Then run the transfer program on hills to place a machine-readable copy of your shell script (which must be named xpinfo ) in your share directory as in all assignments like this:

/pub/cs/gboyd/cs160b/bin/transfer xpinfo

lab5-online CS160B Page 3 of 3

This document was produced with free software: OpenOffice.org on linux.