The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need to write a script in UNIX to find a file if another file exists mmdawg Shell Programming and Scripting 1 05-04-2008 07:40 PM
unix script to check whether particular file exists and to find its size Balachandar Shell Programming and Scripting 9 02-05-2008 12:56 AM
Find lines greater than 80 characters in a file mrgubbala Shell Programming and Scripting 8 03-10-2007 09:51 PM
Can I find wether a particular file exist and size greater than zero...help please guhas Shell Programming and Scripting 4 11-28-2005 10:56 AM
File size greater than 0 skammer1234 Shell Programming and Scripting 1 08-03-2002 07:30 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-23-2002
Registered User
 

Join Date: Jan 2002
Posts: 18
Question file exists and size greater that zero

My problem is that I have to make sure there are no new files being written when I start combining the files other-wise I will get a partial file only. So I am doing a count out to a file and sleeping for a few seconds and doing it again to a different file. I then do a diff on the two files. What I am having trouble with I checking to see if the output file of my diff exists and has a size greater than zero. What I want to do is loop back around and do the counts all over again if there are differences, it not, continue with the rest of the program of combing and moving. Thanks.

#!/usr/bin/perl

LOOP

system("wc IM0106* >count.dat");

system("sleep 5");

system("wc IM0106* >count.dat2");

system("diff count.dat count.dat2 > diff.dat");

if ( (-e diff.dat) && (-z diff.dat) ){
print "File exist and size is 0\n";
system("touch nosize.dat");
exit;}
print "File exist and size is greater than 0\n";

system("sleep 15");

LOOP bach through

END LOOP
Reply With Quote
Forum Sponsor
  #2  
Old 03-25-2002
Kelam_Magnus's Avatar
Registered User
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
This seems like it could be homework, but since you posted your own work instead of asking for us to write your script, I will offer this help.


You need to use awk or cut to parse out the filename from the diff output.

Try this:

1) take whatever field/column is the filename from your diff output.
2) perform the byte size test on the file.


diff file1 file2 |awk -F: '{ print $1 }' > diff.out
if (-z diff.out) etc...


Only use the -F option if you have some delimeter in your output file diff.dat. I only put this in to show you the format. The print $1 is to print the first column of the diff.dat output.

Hope this helps. Again if this is not homework please forgive the assumption.


__________________
My brain is your brain
Reply With Quote
  #3  
Old 03-25-2002
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
I would use a shell script for this. No point in using perl when all you are really doing is making system calls. You can also eliminate the temporary files (unless you need them for some later step)

Code:
#!/bin/bash

while (true)
do
           COUNT=`wc IM0106*`
           sleep 5
           COUNT2=`wc IM0106*`
           if [ $COUNT1 == $COUNT2 ]
           then
                 echo "no difference"
                 touch nosize.dat
                 sleep 15
           else
                 break
           fi
done

# ...  rest of script ...

Note: kelam_magnus posted his reply while I was composing mine. This doesn't sound like a homework problem to me, so I'll leave my script here.
Reply With Quote
  #4  
Old 03-25-2002
Registered User
 

Join Date: Jan 2002
Posts: 18
No this is not a homework problem, something I am doing for work and trying to interface the new EDI system I put in with our legacy system, but I understand your hesitations and appreciate your feedback.

Thanks for the suggestions
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:33 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