shell script to check newly created files in a directory and its sub directories

Shell script to check newly created files in a directory and its sub directories
The below shell script is to monitor a Directory and its sub-directories, and log the information when particular type of files are created/found.

The below script will monitor a directory "/opt/krish" for .sh files.
If there exists any .sh files in the directory (includes sub-directories) it will log the information in the results.log file in the same directory.
It repeats this operation for every 10 seconds so that any newly created file information will be captured.

You can keep on creating some test files using "touch d11.sh" in the same directory to verify whether the same is been logged in the results.log or not.

nc184120:/opt/krish # cat check.sh
#!/bin/ksh
cd /opt/krish
> results.log
date >> results.log
while true
do
    for file in `find . -type f -name "*.sh"`
    do
          ls -lrt $file >> results.log

    done
    sleep 0
done

Read more

Popular Posts

Enter your email address:

Buffs ...

Tags


Powered by WidgetsForFree