Check File Exists and compare to previous day file script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check File Exists and compare to previous day file script
# 1  
Old 02-07-2008
Power Check File Exists and compare to previous day file script

We have data files that are ftp'd every morning to a SUN server. The file names are exactly the same except for that each has the date included in its name. I have to write script to do 2 things:

STEP 1) Verify that the file arrived in morning.
STEP 2) Compare the file size of the current days file to the previous days file. If the current days file size is 30% smaller or less then the previous days, I will need to write a flag/indicator to a log file. (NOTE: The sizes should be very close in size every day, so any decrease to 30% or less would indicate it is missing data.)

Any assistance you can provide is appreciated.
# 2  
Old 02-07-2008
What have you written so far to get started?
# 3  
Old 02-07-2008
To locate the files that have arrived in the morning I am using:

find /<path> -type f -name "eon*.tar.Z" -mtime -1

The part I am not sure about is how to determine if the new file is 30% or less in size compared to the previous days file.

Thanks.
# 4  
Old 02-07-2008
Once know filename

You can determine the filesize with something like:
> ls -l | tr -s " " | cut -d" " -f5

You can learn the filename for the day before with something like:
>find * -mtime -2 -mtime +1

And you are left to combine the logic of the two:
>tfile=$(find /<path> -type f -name "eon*.tar.Z" -mtime -1)
>yfile=$(find /<path> -type f -name "eon*.tar.Z" -mtime -2 -mtime +1)
>tsize=$(ls -l "$tfile" | tr -s " " | cut -d" " -f5)
>ysize=$(ls -l "$yfile" | tr -s " " | cut -d" " -f5)

[I think I have all of that syntax correct Smilie ]

Now, do your math with $tsize for today's file and $ysize for yesterday.
And execute whatever corrective actions are needed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Except script fails to check file exists or not in remote node

Dear members, The following expect script connects to remote node and check for the file "authorized_keys" in directory /root/.ssh in remote node. However the result is always found even if the file exist or doesn't exist. expect { "$fname" { send_user "found\n" } Any idea what is... (4 Replies)
Discussion started by: Sudhakar333
4 Replies

2. Shell Programming and Scripting

Script to check file exists

Hi, I am trying to write a script which checks if any file exists with "*.log" or "*.out" in Directory below is the code #------------------ path=/abd/xyz/ if ; then echo "Good" else echo "Failure" fi #-------------------------- its always going to else part and printing... (8 Replies)
Discussion started by: ch33ry
8 Replies

3. Shell Programming and Scripting

Script to check for the file existence, if file exists it should echo the no of modified days

Hi, I am looking for a shell script with the following. 1. It should check whether a particular file exists in a location #!/bin/sh if ; then echo "xxx.txt File Exists" else echo "File Not Found" fi 2. If file exists, it should check for the modified date and run a command... (2 Replies)
Discussion started by: karthikeyan_mac
2 Replies

4. Shell Programming and Scripting

Script to check if last modified day is previous day

Hi, I would like to write a script that checks if a file ('counter') was modified the previous day, if so erase its contents and write 00000000 into it. For e.g. if the file 'counter' was last modified at 11.30pm on 24th May and the script runs at 12.15am of 25th May, it should erase it's... (1 Reply)
Discussion started by: hegdepras
1 Replies

5. Shell Programming and Scripting

Script to check file with previous date

Hi all,I need your help to create the script.I need a script to check the ZIP file at network location with yesterday date name. ZIP file creation date is current date, but name of the zip file is previous date. for example file name "20110216.zip" created today 201102017.I just want to return the... (1 Reply)
Discussion started by: deepaksingla
1 Replies

6. Shell Programming and Scripting

Script to check if file exists

guys, I am trying to write a script that does the following: it looks for a file in a specific directory and if the file is not there (NOT), it emails me. I have tried the following but its not working. It simply hangs up. Please help. if then mail -s 'blah blah blah' my email... (4 Replies)
Discussion started by: basisvasis
4 Replies

7. Shell Programming and Scripting

Shell script to check if any file exists in 4 folders

Hi All, working on AIX 5.3. Requirement is: Shell script in ksh to check if any file exists in 4 folders as below: 1. /FILE/INB/INT1 2. /FILE/INB/INT2 3. /FILE/INB/INT3 4. /FILE/INB/INT4 Thanks a lot for your time! a1_win. (3 Replies)
Discussion started by: a1_win
3 Replies

8. Shell Programming and Scripting

to write a script to compare the file size in the current directory and previous dir

hi, i am new to this site. i want to write a script to compare the file size of the files in the current dir with the files in the previous directory. the files name will be same, but the filename format will be as xyzddddyymm.txt. the files will arrive with the month end date(i want to... (5 Replies)
Discussion started by: tweety
5 Replies

9. Shell Programming and Scripting

unix script to check whether particular file exists and to find its size

I want to find the size of particular file exists in a particular directory and i wnt to zip it. In the below mentioned code it should check the MQ.log in the particular directory.Please correct my code so that it will check for particular MQ.log but i could not able to check whether the... (9 Replies)
Discussion started by: Balachandar
9 Replies

10. Shell Programming and Scripting

How to compare prev day file to current day file

Hi all: I am new to this board and UNIX programming so please forgive if I don't explain something correctly. I am trying to write a script to keep track of our links, we link one program written for Client A to Client B's directory. What we want to do is to keep track of our linked programs... (1 Reply)
Discussion started by: Smurtzy
1 Replies
Login or Register to Ask a Question