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
Directory sizes loop optimization la_womn Shell Programming and Scripting 6 05-16-2008 08:05 PM
loop through the directory for files and sort by date and process the first file dsdev_123 AIX 1 01-30-2008 01:31 PM
changing filenames in a directory to a number within a loop visitorQ Shell Programming and Scripting 30 12-13-2007 09:43 PM
copy files from one directory to another directory zip_zip UNIX for Dummies Questions & Answers 5 09-14-2003 03:16 PM
moving files from a unix directory to a windows directory gleads UNIX for Dummies Questions & Answers 2 08-29-2002 05:42 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-23-2005
Registered User
 

Join Date: Jun 2005
Posts: 1
Loop through files in a directory

Hi,
I want to write bash script that will keep on looking for files in a directory and if any file exists, it processes them. I want it to be a background process, which keeps looking for files in a directory.
Is there any way to do that in bash script?
I can loop through all the files like this:
for i in `ls -1 \dirname\*`
do
....
done
I can make it an endless loop llike this while [ true ]
do
done
Thanks for all you help.
R
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-23-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,639
Why not run the process in the background ?

rladda.sh

Code:
#! /bin/sh

while true
do
for file in `ls /path/to/dir`
do
[[ -f $file ]] && echo "$file exists"
done
sleep 60
done
Check the /path/to/dir for any file every 60 seconds.

Run the script as

/path/to/rladda.sh &

Vino
Reply With Quote
  #3 (permalink)  
Old 06-24-2005
ssk ssk is offline
Registered User
 

Join Date: May 2005
Posts: 25
Wink why not cron

You can run the script in cron also to check for the file and process the same if it exists. Just a suggestion.
Reply With Quote
  #4 (permalink)  
Old 06-24-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,639
Quote:
Originally Posted by ssk
You can run the script in cron also to check for the file and process the same if it exists. Just a suggestion.
True. cron can be used. And I think it would be a better suggestion than the sleep.

The & makes the script remain alive throughout. If done as a cron job, then once the job is done, the script exits until it is called again.

My 2 cents,
Vino
Reply With Quote
  #5 (permalink)  
Old 06-24-2005
Registered User
 

Join Date: May 2002
Posts: 33
works well. thank you

Alice
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0