eeolivier
asked on
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.
- 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.
ASKER
didn't you forget to refresh test_golden.log ?
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
> 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
ASKER
./check_sync.sh: line 9: syntax error near unexpected token `fi'
./check_sync.sh: line 9: `fi'
./check_sync.sh: line 9: `fi'
ASKER
what mean "if [ -s /home/diff.log ]"
there is no function before -s
there is no function before -s
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> if [ -s /home/diff.log ] then
> /home/subscript.sh
> fi
if [ -s /home/diff.log ]
then
/home/subscript.sh
fi
Wesly
> /home/subscript.sh
> fi
if [ -s /home/diff.log ]
then
/home/subscript.sh
fi
Wesly
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