script to check if new file in folder

I urgently need a small shell script that :

- can be run under cron every minute
- check one folder and launch another script if one file has been ADD, RENAMED or DELETED from this folder.
eeolivierAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wesly_chenCommented:
Hi,

Say the folder is /home/test.
First, generate a log file by "ls -l"
# ls -l /home/test > /home/test_golden.log

> check one folder and launch another script if one file has been ADD, RENAMED or DELETED from this folder
Then the script called /home/test.sh, and another script called /home/subscript.sh
---test.sh --
#!/bin/sh

ls -l /home/test > /home/test.log

diff /home/test.log /home/test_golden.log > /home/diff.log

if [ -s /home/diff.log ] then
   /home/subscript.sh
fi
------------

> can be run under cron every minute
Second, do
# crontab -e
* * * * * /home/test.sh > /dev/nul 2>&1

Regards,

Wesly
0
eeolivierAuthor Commented:
didn't you forget to refresh test_golden.log ?
0
wesly_chenCommented:
Hi,

> didn't you forget to refresh test_golden.log
It depends on what's your subscript.sh.
And "refresh test_golden.log" should be done in the subscript.sh

Wesly
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

eeolivierAuthor Commented:
./check_sync.sh: line 9: syntax error near unexpected token `fi'
./check_sync.sh: line 9: `fi'
0
eeolivierAuthor Commented:
what mean "if [ -s /home/diff.log ]"

there is no function before -s
0
wesly_chenCommented:
[ -s /home/diff.log ]
means if the size of /home/diff.log greater than 0.

Wesly
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wesly_chenCommented:
> if [ -s /home/diff.log ] then
>   /home/subscript.sh
> fi

if [ -s /home/diff.log ]
then
   /home/subscript.sh
fi

Wesly
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.