Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

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.
0
eeolivier
Asked:
eeolivier
  • 4
  • 3
1 Solution
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
wesly_chenCommented:
> if [ -s /home/diff.log ] then
>   /home/subscript.sh
> fi

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

Wesly
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now