#!/bin/sh
. $HOME/.profile
DIRECTORY=/data/tran_data/20170526
LOGDIR=/data/tran_data/20170526/log
LOG=$LOGDIR/countdir.log
begin1=`date +"%m/%d/%Y %T"`
txt_count=0
xml_count=0
map_count=0
other_count=0
mail_user=""
DIRECTORY=$1
if [ "`ls -A $DIRECTORY`" = "" ]; then
echo "$DIRECTORY is empty"
else
echo "$DIRECTORY is not empty"
fi
for file in ` ls $DIRECTORY `
do
if [ -f $DIRECTORY"/"$file ]
then
fileType=${file##*.}
if [ "$fileType" = "txt" ];
then
txt_count=$(($txt_count+1))
elif [ "$fileType" = "xml" ];
then
xml_count=$(($xml_count+1))
elif [ "$fileType" = "map" ];
then
map_count=$(($map_count+1))
else
other_count=$(($other_count+1))
fi
fi
done
echo "'txt file count:'$txt_count" >>$LOG
echo "'xml file count:'$xml_count" >>$LOG
echo "'map file count:'$map_count" >>$LOG
echo "'other file count:'$other_count" >>$LOG
end1=`date +"%T"`
echo "Begin=[ ${begin1} ] - End=[ ${end1} ]">>$LOG
mailx -s "COUNTDIR, Begin=[ ${begin1} ] - End=[ ${end1} ]" ${mail_users} < /data/tran_data/20170526/$LOG