The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How can I find files by date or size from stout? umen UNIX for Dummies Questions & Answers 2 01-13-2008 06:04 AM
shell script to find files by date and size dadadc UNIX for Dummies Questions & Answers 1 10-20-2007 02:18 AM
command to find out total size of a specific file size (spread over the server) abhinov SUN Solaris 3 08-08-2007 03:48 AM
Delete file by date or by size odogbolu98 Filesystems, Disks and Memory 1 03-14-2002 04:00 PM
find the file by size rooh UNIX for Dummies Questions & Answers 1 08-16-2001 04:21 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-08-2008
Registered User
 

Join Date: Apr 2008
Posts: 10
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".

2. 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.
Reply With Quote
Forum Sponsor
  #2  
Old 04-08-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Why is this in the "Advanced" forum? Looks like homework anyway.
Reply With Quote
  #3  
Old 04-08-2008
Registered User
 

Join Date: Apr 2008
Posts: 10
What?

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.
Reply With Quote
  #4  
Old 04-08-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
1.
Code:
#!/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
2.
Code:
awk -F'|'  '{print $1}' number.txt  | read today number
if [[ $today = "`date +%Y%m%d`" ]] ; then 
    printf "%d\n" $number
fi
Reply With Quote
  #5  
Old 04-08-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
I couldn't get the second script to work. (Didn't try the first.) How about this instead:

Code:
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).
Reply With Quote
  #6  
Old 04-08-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
How's this for the first.

Code:
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.
Reply With Quote
  #7  
Old 04-08-2008
Registered User
 

Join Date: Apr 2008
Posts: 10
Input

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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0