dirlist

#This program grabs the directory listing from the
#clients fromclient directory. Determines if it is a
#file, if so it logs in in the csv file. Then it emails
#the file to the users listed in the mailatt.php file.
#
#Requested by Scott

cd /home/list #For crontab reasons. It's lost with out it.

logfile="fromclient`date +%Y%m%d%H%M`.csv" #Initially sets the log file name

echo "This report contains fromclient directory." >> $logfile
dir_list_array=( $(ls /home/ftpusers) ) #Loads ls results into an array
dl_count=${#dir_list_array[@]} #Determines the array length and sets a var
dl_index=0 #Inital set of the index var

while [ "$dl_index" -lt "$dl_count" ] #Loops for each dir name in the array
do
client=${dir_list_array[$dl_index]} #makes code easier to look at

if [[ $client == ftp* ]] #Determines if the dir starts with FTP. If so processes
then
frompath="/home/ftpusers/$client/fromclient" #Once again, to make code easier to read
fromclient_array=( $(ls $frompath) ) #Loads ls results into an array
fc_count=${#fromclient_array[@]} #Determines the array length and sets a var
fc_index=0 #Inital set of the index var

while [ "$fc_index" -lt "$fc_count" ] #Loops for each dir name in the array
do
listfile=${fromclient_array[$fc_index]} #Easier to read
filepath="$frompath/$listfile" #Sets path to actual file
if [[ -f $filepath ]] #Check to see if file or dir
then
# date=`find "$filepath" -prune -printf "%Tm%Td%TY%TT"`
date=`find "$filepath" -prune -printf "%Tc"` #Grabs file date and formats it
echo "$client , $listfile, $date" >> $logfile #Create and append csv file
fi
let "fc_index = $fc_index +1" #Increment counter
done

fi
let "dl_index = $dl_index +1" #Increment counter
done

###########################Non-standard Directories######################

while read ns_dirname
do
ns_array=( $(ls $ns_dirname) ) #Loads ls results into an array
ns_count=${#ns_array[@]} #Determines the array length and sets a var
ns_index=0 #Inital set of the index var

while [ "$ns_index" -lt "$ns_count" ] #Loops for each dir name in the array
do
ns_listfile=${ns_array[$ns_index]} #Easier to read
filepath="$ns_dirname/$ns_listfile" #Sets path to actual file
if [[ -f $filepath ]] #Check to see if file or dir
then
date=`find "$filepath" -prune -printf "%Tc"` #Grabs file date and formats it
echo "$ns_dirname, $ns_listfile, $date" >> $logfile #Create and append csv file
fi
let "ns_index = $ns_index +1" #Increment counter
done
done