#!/bin/ksh # This script adds a user to the file users.ref. # The correct syntax is "add userid fname lname' # The variable error is used to detect errors. error=n # Detect the file users.ref - display error if not found. if [[ ! -a users.ref && "$error" == "n" ]] then echo "Unable to find users.ref file. Try creating a link using 'ln'." echo "User information NOT added." error=y fi # Display error if current login doesn't have write permission for users.ref. if [[ ! -w users.ref && "$error" == "n" ]] then echo "You do not have write permission for users.ref. Try chmod." echo "User information NOT added." error=y fi # Display correct syntax if no arguments are entered. if [[ ! -n "$1" && "$error" == "n"]] then echo "No arguments. The correct syntax is 'add userid firstname lastname'." echo "User information NOT added." error=y fi # Display error and correct syntax if too few arguments are entered. if [[ ! -n "$3" && "$error" == "n"]] then echo "Not enough information. Please enter a userid, a first name, and a last name." echo "Ex: 'add dj1234 John Doe'" echo "User information NOT added." error=y fi # Display error if the new user already exists. if [ "$error" == "n"] then grep $1 users.ref > exists.tmp if [ $? -eq 0 ] then echo "User id already exists in" cat exists.tmp echo "User information NOT added." rm exists.tmp exit 1 error=y fi fi # Detect previous errors. If none, then add user info. if [ "$error" == "n" ] then echo $1 $2 $3 >> users.ref echo "You added $1 $2 $3 to users.ref. If this is incorrect, please use the remove utility." fi