How to make sure dir is really empty


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to make sure dir is really empty
# 1  
Old 03-26-2009
How to make sure dir is really empty

Hi,

I have this piece of shell script:

#!/bin/ksh

x[1]=data1
x[2]=data1
x[3]=data1

for i in 1 2 3
do
cp x[i] $IN_DIR
done
PerformNextTask

$IN_DIR is already designed to automatically pick up x[i] and send x[i] to other directory $OK_DIR. $IN_DIR will be empty once all x[i] goes to $OK_DIR. The speed of the pick up varies, sometimes x[1] takes 10 minutes to be sent to $OK_DIR, x[2] takes 2 minutes to go to $OK_DIR etc.

My problem is, - I want $IN_DIR to be fully emptied (last file x[3]) are picked up and sent to $OK_DIR then only I want to perform another task..

How can this be done?

I tried to do this :
if [`ls -l ${IN_DIR}` == "total 0" ]
then
PerformNextTask

but it's not working.

Can anybody out there help? Smilie
# 2  
Old 03-26-2009
I tried to do this :
if [`ls -l ${IN_DIR}` == "total 0" ]then
PerformNextTask
========================Try this instaed=================
if [`ls ${IN_DIR} |wc -l` == 0]
# 3  
Old 03-26-2009
hey amitranjansahu..

your code works! thank you very much friend for your help Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

2. Shell Programming and Scripting

Why are my text files sometimes empty when I make a read to them?

My implementation: I have a script Caller.sh that runs in the background that continuously calls the following scripts: createtext.sh createtext2.sh createtext3.sh Each of these scripts does the following (but with different text file names): #! /bin/bash ... (1 Reply)
Discussion started by: etranman1
1 Replies

3. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

4. Solaris

/dev/rmt is empty - Trying to make Tape Drive Functional

I have an HP Proliant DL380 with Intel Processors that I recently loaded Solaris 10 with latest patches on it. I'm trying to do a ufsdump to an HP DAT 40 tape drive via SCSI, but I can't get it to do anything because /dev/rmt is empty. I've tried the following with luck: touch /reconfigure,... (7 Replies)
Discussion started by: cvaughn
7 Replies

5. UNIX and Linux Applications

CPIO Problem, copy to the root dir / instead of current dir

HI all, I got a CPIO archive that contains a unix filesystem that I try to extract, but it extract to the root dir / unstead of current dir, and happily it detects my file are newer otherwise it would have overwrited my system's file! I tried all these commands cpio -i --make-directories <... (2 Replies)
Discussion started by: nekkro-kvlt
2 Replies

6. Shell Programming and Scripting

empty the dir

i have dir called stock1. it has some 2000 files How to remove/empty the dir in one shot? i tried this command,but its not working rmdir stock1/* stock1/.* (4 Replies)
Discussion started by: ali560045
4 Replies

7. Shell Programming and Scripting

Delete an empty file from dir.

Hi, I have an dir which has 50K file, some of them are empty. I want to delete the empty file from the dir. I am planning to use the following command. ls -l | grep " 0 " | awk '{print $9}' I can copy this to an file and then how do I use this file to delete the empty files.... Any help... (2 Replies)
Discussion started by: Script40
2 Replies

8. Shell Programming and Scripting

How can I make the for command check to see if a file is empty before executing?

Here is the command in question for f in $(<uploads); do . I only want this to execute if uploads is not empty. If uploads is empty I want the script to quit, actually before the for command. If its not apparent uploads is a text file. Chris (3 Replies)
Discussion started by: chrchcol
3 Replies

9. Shell Programming and Scripting

a script to clone a dir tree, & overwrite the dir struct elsewhere?

hi all, i'm looking for a bash or tcsh script that will clone an empty dir tree 'over' another tree ... specifically, i'd like to: (1) specify a src directory (2) list the directory tree/hiearchy beneath that src dir, w/o files -- just the dirs (3) clone that same, empty dir hierarchy to... (2 Replies)
Discussion started by: OpenMacNews
2 Replies

10. Solaris

cant make dir as root

not sure what the problem is, when I go to /home and enter command mkdir i get this error mkdir chris mkdir: Failed to make directory "chris"; Operation not applicable im root.... (3 Replies)
Discussion started by: csaunders
3 Replies
Login or Register to Ask a Question