CT320 Bash Lab II
Group Project
You may work in pairs, if space demands.
                
Purpose
The purpose of this assignment is to get more experience writing Linux
scripts using bash
and other commands. You will create and edit a
bash script called pwval
that uses many of the features of shell
scripts described in the lecture.
                
Background
The following commands might be useful for this lab:
Also, remember what $#
means in a shell script.
                
Password file entry
Lines in /etc/passwd
looks like this:
                
root:x:0:0:root:/root:/bin/bash
applin:$6$30CrCh90r7Dl5Q4o$uwOkdKHjNkdBLIpreE090Cxt5z0WB765SLXry1QFE8n9fuwYrikKjY37kkPasFwf5My/w2HKgD6kdPsLT0hYV.:2464:1555:Jack Applin:/s/parsons/d/fac/applin:/bin/bash
The fields, separated by colons, are:
                
- username (e.g., “jsmith42”)
- encrypted password
- numeric user ID
- numeric group ID
- user name (e.g., “John Smith”)
- home directory
- shell program
Program
You will write a bash
script called pwval
that ensures
that /etc/passwd
is good. It will:
                
- verify permissions on
/etc/passwd
- no duplicate usernames
- no duplicate userids
- for every entry, verify that:
- the password is non-empty
- the home directory exists
- the shell exists and is executable
- the group exists in
/etc/group
Argument
If an argument is given, then it is a file to be used instead
of /etc/passwd
. This is useful for testing.
                
Messages
Think of this program as something to be executed every day, from cron
.
Therefore, it should be relatively quiet. It shouldn’t say anything,
unless bad things are detected.
                
However, when the script does emit an error message, it must contain
sufficient information to track down the problem. For example, an error
message that simply says “duplicate user name” is insufficient—the message
must specify, at least, what the duplicate user name is.
Line numbers would be even better.
                
All error messages must:
- include the name of the file (not always
/etc/passwd
)
that is being processed
- include
$0
, so that it’s clear where the messages are coming from
- go to standard error, not standard out
- Example:
echo "this is going to standard error" >&2
Temporary Files
To get a temporary file, use mktemp to generate a unique name:
#! /bin/bash
tmpfile=$(mktemp)
echo "My temp file is $tmpfile"
date >$tmpfile
cat $tmpfile
rm $tmpfile
My temp file is /tmp/tmp.F0nO8q30Ar
Sat Nov 23 05:09:53 MST 2024
Get Credit
When you have tested your script, and it works,
show your work to the TA.