UNIX cmd -find empty files in folder else sleep for 8hrs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX cmd -find empty files in folder else sleep for 8hrs
# 1  
Old 02-12-2015
Oracle UNIX cmd -find empty files in folder else sleep for 8hrs

Hello,

I am trying to write a unix cmd , that if files in folder /path/FTP are all zero kb or empty then good to go, if not empty then sleep for 8 hrs.

Following cmd list me the files which are not empty, But when I am incorporating IF ELSE cmd fails

Code:
find /path/FTP. -type f -exec wc -l {} \; | awk '$1 >0 {print $2}'

Any help will be appreciated.
Thanks

Last edited by Scrutinizer; 02-12-2015 at 02:41 PM.. Reason: CODE tags
# 2  
Old 02-12-2015
Please use code tags as required by forum rules!

I'm a bit unsure - how do you want to incorporate IF ELSE in a find command? Did you consider the -size test? You can have two (or more) branches in the find parameters. Read man find.

And, why and how do you differentiate between zero kB and empty?

Please be way more precise with your specification.
# 3  
Old 02-12-2015
Find itself can test for non-empty files, in an if test this could look like:

Code:
if [ -n "`find /path/FTP. -type f -size +0`" ]; then sleep 28800; fi

This User Gave Thanks to Walter Misar For This Post:
# 4  
Old 02-12-2015
Also, you can stop at the first file; use 'read' or 'line' to detect the first line. Be careful of read, as "| read x' in ksh is fine, but in bash, read runs in an implicit subshell and x is not set for your shell, so try explicit subshell in which you test x: '|( read x ; . . . .)'. While 'line' is not a built-in (if you have it at all), it is good at expediting data out of a pipe, where one byte reads are given special treatment, do not block awaiting a bull buffer, and it returns 1 to $? on EOF.

Last edited by DGPickett; 02-12-2015 at 03:07 PM..
This User Gave Thanks to DGPickett For This Post:
# 5  
Old 02-12-2015
Maybe wait and repeat?
Code:
until find /path/FTP. -type f -size 0 | awk '{print; exit 1}'
do
  sleep 28800
done

Instead of until or while you can also use an if clause. It gets the exit status of the awk command, 0 normally, 1 if a zero-file was found.
NB in the shell an exit status 0 is a true condition (for practical reasons).
You can suppress awk's output with >/dev/null, this doesn't affect its exit status.

---------- Post updated at 02:57 PM ---------- Previous update was at 02:49 PM ----------

Just seeing the proposal with line.
Code:
while find /path/FTP. -type f -size 0 | line
do
 sleep 28800
done

# 6  
Old 02-12-2015
Thank You everyone, My problem is solved , If cmd worked for me.
# 7  
Old 02-13-2015
I think in find the size must be '+0' for > 0, else you find empty files.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX one line cmd join 2 sets of data from 2 files

Hi all, This is my first and undoubtedly many posts to come. I'm new to using unix and would like a hand with this problem I have. What i'm trying to do is match 2 sets of data from 2 files and put result into file 3. Sounds simply but there is a catch, the match is a "partial field" match, if... (2 Replies)
Discussion started by: tugar
2 Replies

2. Shell Programming and Scripting

problem with sleep cmd in execution of cron...

I am scheduling a task at regular intervals at seconds acuracy using crond and sleep command . my data in crontab file is as below:- the above line is working fine when we are creating this crontab file before 00:05 min . But when we are creating the crontab file at 00:05min , unable to... (10 Replies)
Discussion started by: manoj424
10 Replies

3. Shell Programming and Scripting

How to find empty files in a directory and write their file names in a text?

I need to find empty files in a directory and write them into a text file. Directory will contain old files as well, i need to get the empty files for the last one hour only. (1 Reply)
Discussion started by: vel4ever
1 Replies

4. Homework & Coursework Questions

Find and delete empty files and directories

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Need to make a script, to remove all empty files and folders from current category. It also should show the name... (2 Replies)
Discussion started by: Itixop
2 Replies

5. Shell Programming and Scripting

Unix cmd prompt how to get old cmd run?

Hi, I am using SunOS I want to serch my previous command from unix prompt (like on AIX we can search by ESC -k) how to get in SunOs urgent help require. (10 Replies)
Discussion started by: RahulJoshi
10 Replies

6. Shell Programming and Scripting

Find all text files in folder and then copy to a new folder

Hi all, *I use Uwin and Cygwin emulator. I´m trying to search for all text files in the current folder (C/Files) and its sub folders using find -depth -name "*.txt" The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Discussion started by: cgkmal
4 Replies

7. Shell Programming and Scripting

using find cmd to find certain files

i have a list of files below: rwxrwxrwx 1 pipe pipe 180 Mar 4 22:47 del_0n_Date -rwxrwxrwx 1 pipe pipe 472 Mar 4 22:58 mail_Check -rw-r--r-- 1 pipe pipe 92 Mar 4 22:58 minfo.txt -rwxrwxrwx 1 pipe pipe 609 Mar 5 05:12... (6 Replies)
Discussion started by: ali560045
6 Replies

8. UNIX for Dummies Questions & Answers

How to find files not empty?

Is there any way, we can find files not empty? I know one can find empty files by using find with -size is equalled to 0. Please let me know, how I can find files greater than 0 or any other size in number? (2 Replies)
Discussion started by: videsh77
2 Replies

9. UNIX for Dummies Questions & Answers

move files from folder thats are not empty

Hi, I would like to write a shell script that moves files from one folder to another without retrieving the error 'can not find file or folder' when the folder is empty. Any ideas, Thx in advance, Steven. (8 Replies)
Discussion started by: Steven
8 Replies

10. Shell Programming and Scripting

Suppres error message when moving files from empty source folder

Hi, I would like to write a shell script that moves files from one folder to another without retrieving the error 'can not acces/find file or folder' when the source folder is empty. Any ideas, Thx in advance, Steven. (2 Replies)
Discussion started by: Steven
2 Replies
Login or Register to Ask a Question