CSCI 257: Fundamental UNIX System Administration
Class Project for Spring 2003
The goal of the class project is to provide students with practical experience
to administer Linux installation and administration on a computer shared
with Windows.
Laboratory Assignment 7
ASSIGNMENT DUE: 12:00 NOON, April 9, 2003.
Assignment Description:
As a system administrator, you will want to automate some tasks to be
efficient, reduce chance for errors and avoid the extreme boredom found in
repetitive tasks. Shell scripting allows automation of many tasks.
Goal:
The goal of this assignment is to introduce students
to the use of shell scripting to help automate system administration tasks.
Objectives:
- Write a shell script to automate some tasks associated with managing
a large number of user accounts on a system.
- The script should allow for adding, disabling, and deleting a large
number of user accounts.
Expected Outcome:
- The student will write a script called usertool
- Imagine an environment much like our school where a large numbers
of students need user accounts to be either added, disabled or deleted from
a system. Rather than have an administrator add each account by hand
we would like to automate the task by having a script read a datafile and
and then automatically create accounts for each student. Likewise
for disabling and deleting accounts.
- usertool will be used in the following manner
- usertool add datafile [group] - usertool reads the
datafile and creates accounts for each user. Optionally a group name
can be specified and these new user accounts will be created as members
of that group (if a group name is not specified users will be added to the
default group for the system, like "users" for example).
- usertool disable datafile - usertool reads the datafile
and disables the account for each user in the datafile.
- usertool delete datafile - usertool reads the datafile
and deletes the account including the home directory for each user in the
datafile from the system.
- usertool - usertool called with no options or invalid options
will print a "usage message", for example, type 'grep' with no options to
see what a "usage message" is. Invalid options include 'usertool
delete' with no datafile specified and 'usertool something random',
with some options other than those listed above.
- The datafile will have the format: "FirstName LastName
SocialSecurityNumber TelephoneNumber Sex State"
with fields seperated by tabs, for example:
Joe Smith 123456789 5305551001
M CA
Sally Jones 123456789 5305551234
F CA
- Imagine this file is something generated by something like Records
and Registration each semester. It is emailed to the system administrator
as a list of students to be added to the system. A datafile in the
same format is emailed as at the end of each semester as a list of students
who are no longer attending the school and whoose accounts can be removed.
Also imagine there is a policy for removing accounts which involves
first disabling them (in case a few accounts need to be re-enabled for some
reason) and then 6 or so months later deleting them. Our script will
help us automate these tasks.
- User names will all lower case and will be created by concatenating
the students first initial and last name (for example, "Sally Jones"
gets the username "sjones"). Social security numbers will be used
for passwords. Full names, for example "Joe Smith", should also be
passed to useradd so that they show up in the fifth field of /etc/passwd.
The phone number, sex and state fields are ignored by our script.
- All first initial / lastname combinations in the file will be unique
so you don't have to worry about conflicts like "Joe Smith" and "Jack Smith"
both reducing to the user name "jsmith". Also, you don't have to worry
about tricky things like last names which are more than one word and include
a space or hyphen in the middle.
- Datafiles can have any number of records and can have any name (in
other words datafiles won't be named "datafile").
- Implementation
- Scripts may be implemented using your choice of sh, ksh, bash,
csh, tcsh, or perl (Ask me if you want something else added to this list).
- You probably want to use expect for interacting with passwd
(if you know some different way that's fine you don't have to use expect).
- Scripts should not directly modify /etc/passwd but should use useradd,
usermod, userdel and passwd for modifying /etc/passwd.
- You can use multiple scripts to get the job done, for example,
usertool could call another script you might write called setpassword
for setting the password for each account.
- Your script can use any common unix utilities like cat,
sed, awk, etc. if need be.
- Your script must include minimal documentation:
- In the header include:
- your full name
- date
- course
- short description of script
- Maybe include a few lines of comments in the body of the script
to help make it more readable.
- usertool called with no options will print a short "usage:"
message like a lot of unix utilities do.
- Turn-IN
- Cover page - Your Name, Course, Date, Lab Number
- Printout of script(s)
- A little evidence that your script works:
- Add a group to your system called "students".
- Run usertool add datafile students with
the provided sample datafile sample-data.
- Make a copy and printout of /etc/passwd (which will show the
user accounts added).
- Make a copy and printout of /etc/shadow
- Run usertool disable datafile with the provided
sample datafile sample-data.
- Make a copy and printout of /etc/shadow