\documentclass{ictlab}

\RCS $Revision: 1.2 $

\usepackage{verbatim,alltt}
\usepackage[pdfpagemode=None,pdfauthor={Nick Urbanik}]{hyperref}

\newcommand*{\labTitle}{Using Regular Expressions to Create User Accounts}

\begin{document}
For each exercise where you write a program, keep the original program
from each exercise and modify a copy for the next exercise.

\section{Background}
\label{sec:background}

There are many ways of creating accounts on a Linux system; your
program could select the next available user and group \acro{ID}s,
manually edit the \texttt{/etc/passwd}, \texttt{/etc/group} and
\texttt{/etc/shadow} files, create the user directories, copy the
login scripts and other basic account files from \texttt{/etc/skel},
and change the ownership to the new account, but a simpler and more
portable way is to use the standard \texttt{useradd} program that you
learned about last year.  We can call that from our own Perl programs
using the built-in \texttt{system} function.

Today we will write a program that will create a user account for each
student listed in the artificial student registration data.

\paragraph{Procedure:}
 
\begin{enumerate}
\item Download the artificial student data from
  \url{http://nicku.org/snm/lab/regular-expressions/artificial-student-data.txt}.
  This file is in the old format of the student registration system,
  but contains no real data about any student.

\item Write a Perl program that can read all the lines of this file
  when it is given as a command line parameter, and print the student
  numbers only, one to each line.

\item Make a copy of your program, and modify it so that it prints
  only the names of the students, one to each line, with no extra
  spaces either at the beginning or end of each name.

\item Using the manual page for the \texttt{useradd} program as a
  guide, modify your previous programs so that your program prints one
  \texttt{useradd} command for each student, using the student
  \acro{ID} as the login \acro{ID}, the Hong Kong \acro{ID} as the
  password, and the name of the student as a comment.
  
  Note that our Linux systems require that the user/group names must
  start with a letter, and may not contain colons, commas, newlines or
  any non-printable characters.  The maximum length of the user
  \acro{ID} is 32 characters; that of the group \acro{ID} is 16.  To
  meet this requirement, make the user \acro{ID} be the first letter
  (made lower case) of the family name, followed by the student
  \acro{ID}.

\item Modify this last program further so that it uses the built-in
  Perl function \texttt{system} to execute the \texttt{useradd}
  command as well as print the command.  Type \texttt{perldoc -f
    system} to read about this important function.

\item Modify your last program so that it reports an error message if
  the execution of any \texttt{useradd} command is unsuccessful.
\end{enumerate}
\end{document}
