As bgeddy said, the cat method works well if your list file contains one user name per line... it sounds like that may not be the case.
I've modified this script from above in a trivial manner to use that method and added quotes around the contents of the .forward file entry in the log.
Code:
#!/bin/bash
logfile="/root/forwardlog.txt"
INPUTFILE=/root/usernames
for name in $(cat $INPUTFILE)
do
file=/eng/$name/.forward
if [ ! -e $file ]; then
echo "File $file does not exist. Writing to Log."
echo "Missing File $file" >> $logfile
else
echo "File Exists, logging entry to file"
echo "Entry for user $name is \"`cat $file`\"" >> $logfile
fi
echo
done
exit 0
I created this input file (named /root/usernames):
Code:
tom
dick
harry
maryjane
and made the appropriate directories and files.
The directory "maryjane" does not contain a .forward file, all of the rest have valid entries.
I get this output on the screen:
Code:
File Exists, logging entry to file
File Exists, logging entry to file
File Exists, logging entry to file
File /eng/maryjane/.forward does not exist. Writing to Log.
and this is the resulting log file:
Code:
Entry for user tom is "abuse@google.com"
Entry for user dick is "nobody@home.com"
Entry for user harry is "root@whitehouse.gov"
Missing File /eng/maryjane/.forward
About the only thing I can think of to make it more informative might be to list the successful file names on the console but they're logged so I didn't mess around with your original output.