Find file size and date

Hi in my shell script I have to do this

  1. there is a file called testing.txt in /home/report directory

If the file size is 0(zero) and date is today's date, then I have to print
"Successful" else "Failed".

  1. There is a file called number.txt which will have text only one line like this

20080324|0000040768

the first 8 digits is date. I have to check if that date is today's date, if so print 40768.

I mean I have to trim 0000040768 to 40768.

Any help is appreciated.

Regards,

G.

Why is this in the "Advanced" forum? Looks like homework anyway.

your perception is wrong

Any body who is expert in a different field and had to get some work done in unix can post such questions.

Could help you if you have any doubts in ORACLE.

Regards,

G.

#!/bin/ksh
touch -t `+%Y%m%d0000` ./dummy
count=0
find  /home/report -name testing.txt -newer ./dummy | \
while read file
do
    let count=$count+1
done
if [[ $count -eq 1 ]] ; then
   echo "Success"
else
   echo "Failure"
fi

awk -F'|'  '{print $1}' number.txt  | read today number
if [[ $today = "`date +%Y%m%d`" ]] ; then 
    printf "%d\n" $number
fi

I couldn't get the second script to work. (Didn't try the first.) How about this instead:

IFS='|' read date number <number.txt
case $date in `date +%Y%m%d`) printf "%d\n" "$number";; esac

Thanks for the printf idea; I would have used sed or something but this is neater (provided you have printf).

How's this for the first.

if find /home/report -maxdepth 1 -mtime -1 -name testing.txt -size 0 | grep . >/dev/null 
then
  echo Success
else
  echo Failure
fi

The find is slightly inexact; if your find has the -daystart option then that will fix the date calculation.

Hi,

really appreciate the input but still throwing errors

first one error

find: 0652-017 -maxdepth is not a valid option.

secon one error

printf: 3016-002 00004268 is not completely converted.

Any Ideas plz.

Regards,

G.

-maxdepth is perhaps not strictly necessary in practice; I put it in in case you have subdirectories (especially, lots of subdirectories)

What's 3016-002? Do you mean to say you still get the leading zeros? Try this instead, maybe?

awk -v n="$number" 'BEGIN { printf "%d\n", n }' </dev/null

That's a bit of a hack though.

hi Era,

The second one is working awesome.

for the first one

if find /hone/report/wedm -mtime -1 -name MBRSHIP.TXT -size 0 | grep . >/dev/null
then
echo Success
else
echo Failure
fi

it is giving failure though the filesize is 0?

Please help.

Regards,

G.

Works for me. What's the file's date?

I am really sorry Era,

Didnt see that. Now it works.

Thanks and lot for the input.

Thanks and regards,

G.