LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-25-2008, 03:25 AM   #1
seanys
LQ Newbie
 
Registered: Feb 2006
Posts: 8

Rep: Reputation: 0
Unhappy Scripting: testing for zero byte files


Hi all,

I have batch job that loads data from text files that are deposited by another system.

I need to modify the current script so that it doesn't proceed to rsync'ing if any of the files are empty.

Eg.
Code:
if [one or more files are empty]
then
     abort
else
     rsync
fi
I know that `find /dir/dir/ -size 0` will find empty files but I can't figure out how to get that into a script to test for 'true' or 'false' or how to loop through the possible multiple lines returned.

Sean.
 
Old 03-25-2008, 03:32 AM   #2
livetoday
Member
 
Registered: Jun 2006
Location: India
Distribution: RHEL,Suse,Fedora
Posts: 106

Rep: Reputation: 15
See if it helps ....

Quote:
if [ -s "$1" ]
then
echo "file is not empty"
else
echo "file is empty"
fi
 
Old 03-25-2008, 04:23 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
You can try a slightly different approach using the --exclude option of rsync
Code:
for file in `find /dir/dir -size 0`
do
   EXCLUDE="--exclude=$file $EXCLUDE"
done

rsync -avz --delete $EXCLUDE -e ssh /source/dir 192.168.0.1:/destination
In this way you build a list of --exclude options, one for each zero-length file. Then insert it in the rsync command line: in this way all files will be rsynced except the empty ones.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to copy an entire disk byte-for-byte Pawprint Linux - Software 6 06-16-2011 11:01 AM
byte to byte remote comparison louisJ Linux - Newbie 3 09-21-2007 05:28 PM
bash scripting testing for file exvor Programming 4 08-08-2007 03:42 PM
Emacs: source not byte files on Breezy? TippExed Linux - Software 0 10-24-2005 11:51 AM
Setup as getting debian testing files from ftp - will it stay with testing BrianHenderson Debian 2 09-02-2004 06:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration