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
Why not run the process in the background ?
rladda.sh
#! /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
1 Like
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
works well. thank you
Alice