CONTENTS:

Quick Start

There are five scripts that control the addition and deletion of user accounts:

THE SCRIPTS

DATA FILES:

There are four types of data files that these scripts use:

THE DATA FILES

Quick Start

To add a course/users

Note: Use whatever means of editing termyear.data that you are comfortable with, be it vi, cat, etc.

$ su -
#
# cd /export/home/a/admin/bin/
# cat >> spring2010.data
mue3693 0001 ksh 0515170010 Dr. Professor
^D
# tail spring2010.data # unecessary, but just to double-check
mue3693 0001 ksh 0515170010 Dr. Professor
# ksh createGENfiles.ksh spring2010.data
Using spring2010.data for input
Evaluating mue3693 0001... done: Created EXA1000-0001.gen: 14 records
# ksh addusers.ksh EXA1000-0001.gen
First available UID = 8494

[if user is added successfully:]
Adding: bh90210 UID: 8494 GID: 60 Encrypting Password...Creating home and importing files...done

[if user already exists:]
User bh90210 (UID:8494) exists: Resetting password
# tail /etc/passwd # unecessary, but just to double-check
bh90210:x:8494:60:Beverly C. Hills:/export/home/b/bh90210:/usr/bin/ksh
# exit

To delete a course/users

$ su -
#
# cd /export/home/a/admin/bin/
# ksh delusers.ksh EXA1000-0001.gen
[if user does not exist:]
Account bh90210 not live in /etc/passwd: checking for home directory...No home directory exists, skipping
Account bh90210 not live in /etc/passwd: checking for home directory...Files found and removed

[if user does not own their home directory: user is not removed! requires manual removal!]
UX: userdel: WARNING: bh90210 has no permissions to use /export/home/b/bh90210.

[if user has no home directory: user is not removed! requires manual removal!]
UX: userdel: ERROR: Unable to find status about home directory: No such file or directory.

[for proper/regular deletion:]
Removing bh90210 (Beverly C. Hills)
# exit

Deleting all students from /etc/passwd

$ su -
#
# cd /export/home/a/admin/bin/
# ksh delusers.ksh /etc/passwd
Deleting all student accounts from /etc/passwd
Remove ALL student accounts from /etc/passwd? [y/n] y
Removing bh90210 (Beverly C. Hills)
# exit

Using addall.ksh

$ su -
#
# cd /export/home/a/admin/bin/
# ksh addall.ksh -y
Adding users from EXA1000-0001.gen
First available UID = 8494
Adding: bh90210 UID: 8494 GID: 60 Encrypting Password...Creating home and importing files...done
[...]
Adding users from EXA1001-0001.gen
First available UID = 8508
Adding: la90210 UID: 8508 GID: 60 Encrypting Password...Creating home and importing files...done
[...]
# exit

Using delall.ksh

$ su -
#
# cd /export/home/a/admin/bin/
# ksh delall.ksh -y
Deleting all student accounts from EXA1000-0001.gen
Removing bh90210 (Beverly C. Hills)
[...]
Deleting all student accounts from EXA1001-0001.gen
Removing la90210 (Los C. Angeles)
[...]
# exit

ALL OF THE SCRIPTS:

THE SCRIPTS

createGENfiles.ksh

This script is used to create individual .gen files. It requires a termyear.data formatted file as input. It uses line12.data and line3.data to process.

addall.ksh

This script is used to mass-add courses. It uses .gen files. When executed it will add users for all .gen files in /export/home/a/admin/bin/. This is useful at the beginning of semesters when you would like to add multiple courses at one time, rather than manually re-running addusers.ksh for each course. Because this file calls addusers.ksh, and addusers.ksh creates backups of /etc/passwd and /etc/shadow, running this script creates those backups.

addusers.ksh

This script uses .gen files for input. It verifies that the user does not exist on the system (if they do, their files are left intact but their password is reset), creates their home directory and gives them basic files (from /etc/skel), encrypts their password and adds them to passwd and shadow, and creates a quota for them. Everytime this script is run, it creates a dated backup-file of /etc/passwd and /etc/shadow. It names them /etc/passwd-DATE, where DATE is the output of the system date(1) command.

delall.ksh

This script is used to mass-delete students. It uses .gen files. When executed it will delete users for all .gen files in /export/home/a/admin/bin/. This is useful at the end of a semester when you would like to delete multiple courses at one time, rather than manually re-running delusers.ksh for each course. Because this file calls delusers.ksh, and delusers.ksh creates backups of /etc/passwd and /etc/shadow, running this script creates those backups.

delusers.ksh

This script uses .gen files for input or /etc/passwd. It verifies whether or not the student exists in /etc/passwd, whether or not they own their home directory, whether or not that have a home directory, and removes them. It will not remove a user if they do not have a home directory or do not own their home directory. When using /etc/passwd as the input (ksh delusers.ksh /etc/passwd) you will be asked to verify (with a "y") "Remove ALL student accounts from /etc/passwd? [y/n]" This will remove the account of every user on the system who is in group 60, students. This is useful at the end of a semester or year after grading is over to purge all student accounts. Everytime this script is run, it creates a dated backup-file of /etc/passwd and /etc/shadow. It names them /etc/passwd-DATE, where DATE is the output of the system date(1) command.<

THE DATA FILES

line12.data

line12.data is a file from the registrars each semester. It holds a unique-identifier at the beginning of each line which correlates to a student. The following data is then the course prefixes and section numbers that each student is taking.

line3.data

line3.data is a file from the registrars each semester. It holds a unique-identifier at the beginning of each line which correlates to a student. The following data is the PID, NID, default password, then student name.

course.gen

course.gen is a file created as the output of createGENfiles.ksh

termyear.data

termyear.data is a file created by the user. This file is space or tab delimited. This file is used to create all .gen files. The format is:

mue3693  0001   ksh   0515170010 Dr. Professor
mus2360c 0001   ksh   0515170010 Dr. Professor
cop3400  a001   ksh   0515170010 Dr. Professor
The fields are course prefix, course number, section number, shell, expiration date, then professor's name.
The course prefix (three leading letters) is expected to be in lower-case. It will parse as upper-case though.
Summer courses, where the section may be prefixed with A, B, C, or D, the letter is expected to be in lower-case. It will parse as upper-case though.