Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
i need a script which shd run for infinate loop and it should poll the current directory (excluding sub-directories)and whenevr a new *.txt comes, it shd call other script say temp.sh with this new *.txt as argument and once the processing is done, it shd poll again.

It's simple enough. Assume your test program, test.ss, looks like this:
#!/bin/ksh# test.ss
# your PATH maybe different
PATH=/usr/bin:/usr/sbin:/sbin:/usr/sfw/bin:/usr/sfw/sbin# your current directory will be different
cd /home/nails/mytmp
ls -1 *.txt 2> /dev/null|while read file
do
echo "$file"
# execute what you want to
#
rm "$file"
donecron, if set up correctly, can execute this ever minute. Here is how to do it.
# it's always a good idea to save your user's cron file:
crontab -l > mycronfile
Now, place this line in mycronfile:
* * * * * /path/to/test.ss
This will execute test.ss every minute.
To implement the cron command:
crontab < mycronfile
execute
crontab -l
to ensure the command now exists in cron.
Not every Unix user is set up to execute cron. If you can't, the system administrator can grant users cron permissions.

In windows, I would do something like the following. In UNIX something similar ? (This is written in biterscripting (http://www.biterscripting.com) , but any scripting language will do.)
Let's assume that you are looking for .txt files in C:/mydir.
var str currentFileList
var str oldFileListwhile (true)
do
lf -n "*.txt" "C:/mydir" > $currentFileList
if ($currentFileList <> $oldFileList)
# File list has changed - do something
endifset $oldFileList = $currentFileList # for next time
sleep 5 # Sleep 5 seconds
doneHope this helps.
Randir Randwa

![]() |
Script to find whether li...
|
extra entry when joining ...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |