HI,
I have wrote a script which reads in a file that has a list of files within it.
The script then searches the directory for these files and when found will output to an email with a layout table indicating the date of the file and an ok status if the file = todays date if not a waiting appears. (it is to show the recipient that they need to chase for the waiting files).
two of the files are todays date - jkl.csv and stu.txt the rest are either blank or not todays date.
The problem i have is that i cannot get the waiting / ok to work. The script below is outputting all files to warning when in fact all should be warning except jkl.csv and stu.txt???
script is:
#!/bin/ksh
###########
#VARIABLES#
###########
RUNREF=`date +%Y%m%d`
FILE_LIST="../parms/files.txt"
Subject="xxx File Check"
EMAIL="cdmspb"
MAIL_FROM="xxx"
LOG_DIRECTORY="../logs"
MSG_DEST="${LOG_DIRECTORY}/${RUNREF}_build.log"
argv0=`basename $0`
fsz=47
ul="-----------------------------------------------"
ck="+"
cs="|"
###########
#FUNCTIONS#
###########
writelogf()
{
if [ $# -gt 9 ]
then
printf "Unable to generate requested error line\n"
exit 1
fi
args=$#
case $args in
1) printf "$1" >&2;;
2) printf "$1" "$2" >&2;;
3) printf "$1" "$2" "$3" >&2;;
4) printf "$1" "$2" "$3" "$4" >&2;;
5) printf "$1" "$2" "$3" "$4" "$5" >&2;;
6) printf "$1" "$2" "$3" "$4" "$5" "$6" >&2;;
7) printf "$1" "$2" "$3" "$4" "$5" "$6" "$7" >&2;;
8) printf "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" >&2;;
9) printf "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" >&2;;
esac
case $args in
1) printf "$1" >>$MSG_DEST;;
2) printf "$1" "$2" >>$MSG_DEST;;
3) printf "$1" "$2" "$3" >>$MSG_DEST;;
4) printf "$1" "$2" "$3" "$4" >>$MSG_DEST;;
5) printf "$1" "$2" "$3" "$4" "$5" >>$MSG_DEST;;
6) printf "$1" "$2" "$3" "$4" "$5" "$6" >>$MSG_DEST;;
7) printf "$1" "$2" "$3" "$4" "$5" "$6" "$7" >>$MSG_DEST;;
8) printf "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" >>$MSG_DEST;;
9) printf "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" >>$MSG_DEST;;
esac
}
get_time_stamp()
{
ts_time=`date +"%H:%M:%S"`
ts_date=`date +"%B %d %Y"`
}
start_msg()
{
get_time_stamp
writelogf "\n$MSG search initiated at $ts_time on $ts_date\n\n"
}
end_msg()
{
get_time_stamp
writelogf "\n$MSG search completed at $ts_time on $ts_date\n"
}
email_user()
{
#Email
mail -t "$1" << EOF
Subject: $3
From: $2
$4
$5
EOF
}
#############
#MAIN SCRIPT#
#############
STATUS="OK"
MSG="Waiting for xxx files"
start_msg $STEP $MSG
writelogf "$argv0:+%-${fsz}.${fsz}s-%-${fsz}.${fsz}s-%-${fsz}.${fsz}s+\n" $ul $ul $ul
writelogf "$argv0:|%-${fsz}.${fsz}s${cs}%-${fsz}.${fsz}s${cs}%-${fsz}.${fsz}s${cs}\n" "FILE" "DATE" "STATUS"
writelogf "$argv0:|%-${fsz}.${fsz}s${ck}%-${fsz}.${fsz}s${ck}%-${fsz}s|\n" $ul $ul $ul
while read FILE
do
file_date=`ls -l $FILE | nawk 'BEGIN {FS=" "}{ printf "%s %s\n", $6, $7}'`
MONTH=`date +"%b" | cut -d" " -f1`
DAY=`date +"%e" | nawk '{ printf "%d\n", $0}'`
todays_date="$MONTH $DAY"
if [[ ( "$FILE" == " " ) || ( ! -r $FILE ) || ( $file_date != $todays_date ) ]]
then
STATUS="WAITING"
fi
#echo "file [$FILE] [$STATUS]"
writelogf "$argv0:|%-${fsz}.${fsz}s${cs}%-${fsz}s${cs}%-${fsz}s${cs}\n" $FILE "$file_date" $STATUS
done < $FILE_LIST
writelogf "$argv0:+%-${fsz}.${fsz}s-%-${fsz}.${fsz}s-%-${fsz}.${fsz}s+\n" $ul $ul $ul
end_msg $STEP $MSG
#email all users
mailx -r $MAIL_FROM -s "xxxx File Check" $EMAIL < $MSG_DEST
rm $MSG_DEST
output email is below:
Code:
Waiting for xxxx files search initiated at 10:55:40 on June 23 2008
test3.sh:+-----------------------------------------------------------------------------------------------------------------------------------------------+
test3.sh:|FILE |DATE |STATUS |
test3.sh:|-----------------------------------------------+-----------------------------------------------+-----------------------------------------------|
test3.sh:|/abc.txt |Jun 19 |WAITING |
test3.sh:|/def.out |Jun 19 |WAITING |
test3.sh:|/ghi.dat |Jun 19 |WAITING |
test3.sh:|/jkl.csv |Jun 23 |WAITING |
test3.sh:|/mno.txt |Jun 11 |WAITING |
test3.sh:|/pqr.dat |Jun 11 |WAITING |
test3.sh:|/data/stu.txt |Jun 23 |WAITING |
test3.sh:|/vw.dat | |WAITING |
test3.sh:|/xy.dat | |WAITING |
test3.sh:|/z11.dat | |WAITING |
test3.sh:+-----------------------------------------------------------------------------------------------------------------------------------------------+
Waiting for xxxxx files search completed at 10:55:41 on June 23 2008