Script for automatic count the file i have

Hi

I have a folder will all the file ftp in everyday. I have to go in every morning to check to see everynight have all the 2000+ file have been all FTP in.

so every morning i will check like this

# ls -l *_20080904*_20080904* |wc

if there is 2714 that mean is correct.

File name: summer_3024190_200809041200_2008090413000.csv

Can someone help me to generate a script so that everyday i just need to check the log file will do?

Thanks in adv

Summer

Try this.. If I dont get your question wrong... :o

#!/bin/ksh
cd /
lines=`ls -l *_20080904*_20080904* |wc -l`
if [ ${lines} -eq 2714 ]
then
echo "Good"
exit 1
else
echo "Bad"
fi

Hi

erm well 20080904 is a data of yesterday. can the script grep yesterday automatic?

sumemr

Do you have the GNU date command? If so you can try:

YESTERDAY=$(date --date yesterday +%Y%m%d)
lines=$(ls *_${YESTERDAY}*_${YESTERDAY}* |wc -l)

Sorry, I really don't understand your statement

Humm i guess i don have GNU date command.
is there other way?

Summer

Perhaps you could say what operating system and shell you are using so we can better answer your question.

i'm using solaris 9 and ksh.

i'm using solaris 9 & ksh.

ksh works for all and I dont foresee any issues with that. Maybe you can be clear enough to elaborate what you want to achieve., at least by providing some sample outputs..? :confused:

Try this perhaps:

#!/bin/ksh
cd /some/folder
YESTERDAY=$(perl -e 'use POSIX;print strftime("%Y%m%d\n",localtime(time-86400));')
lines=$(ls *_${YESTERDAY}*_${YESTERDAY}* |wc -l)
if [ "${lines}" -eq 2714 ]
then
    echo "Good"
else
    echo "Bad"
    exit 1
fi

Thank all for the help. Annihilannic you script works^^

Thanks thanks..
Summer

I had a similar problem where I had to get a value based on yesterday. I came up with the following script. I'm sure it could be shortened a bit but it works for me. Here you go...

#!/usr/bin/ksh
#
#

# Use the built-in time command to get the epoch
# time of yesterday. 86400=1 day in seconds.

YESTER_EPOCH=`/usr/bin/perl -e 'printf"%d\n",(time-86400);'`

# Now convert the epoch time into something more usable.

YESTERDAY_TEMP=`perl -e "print scalar(localtime(${YESTER_EPOCH}))"`

# Now parse out the month, day, and year.

MONTH_TEMP=`print ${YESTERDAY_TEMP} | cut -d" " -f2`

DAY_TEMP=`print ${YESTERDAY_TEMP} | cut -d" " -f3`

YEAR=`print ${YESTERDAY_TEMP} | cut -d" " -f5 | cut -c3-4`

# Convert the month text into a number format

case "${MONTH_TEMP}" in
Jan)
MONTH=01
;;
Feb)
MONTH=02
;;
Mar)
MONTH=03
;;
Apr)
MONTH=04
;;
May)
MONTH=05
;;
Jun)
MONTH=06
;;
Jul)
MONTH=07
;;
Aug)
MONTH=08
;;
Sep)
MONTH=09
;;
Oct)
MONTH=10
;;
Nov)
MONTH=11
;;
Dec)
MONTH=12
;;
esac

# Convert the day to 2 digits if not already

case "${DAY_TEMP}" in
1)
DAY=01
;;
2)
DAY=02
;;
3)
DAY=03
;;
4)
DAY=04
;;
5)
DAY=05
;;
6)
DAY=06
;;
7)
DAY=07
;;
8)
DAY=08
;;
9)
DAY=09
;;
*)
DAY=${DAY1_TEMP}
esac

# From here you can continue with the code that INCREDIBLE posted above.

MYDATE=`ls -l *_${YEAR}${MONTH}${DAY}*_${YEAR}${MONTH}${DAY}* | wc -l`

if [ ${MYDATE} -eq 2714 ]
then
echo "Good"
exit 1
else
echo "Bad"
fi

Hope this is what you're trying to do.

Bruhn

Oh Sorry.... I didn't see page 2. Someone already posted the answer.