#!/bin/sh -u # $0 [ filenames... ] # Prompt for a userid. Email each file to that userid. # -IAN! idallen@ncf.ca export PATH=/bin:/usr/bin umask 022 # Validate all the file names before we begin. # The status variable is set to 1 if we have any errors. # The countokay variable is set to 1 if we find at least one good file. # status=0 countokay=0 for file do echo "The arg is $file" if [ ! -r "$file" ]; then echo 1>&2 "$0: '$file' is not readable" status=1 fi if [ ! -f "$file" ]; then echo 1>&2 "$0: '$file' is not a file" status=1 fi if [ ! -s "$file" ]; then echo 1>&2 "$0: '$file' is empty" status=1 fi countokay=1 # found at least one good file done if test "$status" -eq 1 ; then echo 1>&2 "$0: There was an error; no files processed." exit 1 fi if test "$countokay" -eq 0 ; then echo 1>&2 "$0: Cannot find any file names to email. Nothing done." exit 1 fi # prompt for (on standard error), read, and echo a userid # echo 1>&2 "Please enter a userid:" read userid echo "You entered '$userid'" # Loop for each file, mailing it to the userid. # Exit if the mail command fails. # for file do # Don't actually do this mailing! Print a DEBUG line instead. echo "DEBUG mail $userid <$file || exit $?" # Same code as above, but using "if" instead of "||". #if ! echo "mail $userid <$file" ; then # exit $? #fi done