Shell / Perl script to constantly comb a folder for new files & make copies of the new files

sunhux
sunhux used Ask the Experts™
on
http://www.experts-exchange.com/questions/28922803/Windows-batch-powershell-VB-scripts-to-constantly-comb-a-folder-for-new-files-make-copies-of-the-new-files.html

Refer to above EE link.  I have a similar requirement for RHEL 5/6 & Solaris as well, so
will need Shell / Perl scripts or any other solutions
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017
Commented:
are you using qlemo's example, you can use a shell script that will use find -newer reference_file

#!/bin/sh
Quarantine='path_to_quarantine'
Analysis='path_to_analysis'
Root_path='path_of_operation'
if test ! -f "$Root_path/First_run" ; then
    cp -r "$Quarantine/*" "$Analysis"
    touch "$Root_path/First_run"
    touch "$Root_path/last_run"
    exit;
fi
find $Quarantine -newer "$Root_path/last_run" -exec cp {} "$Analysis/" \;
touch "$Root_path/last_run"

Open in new window


the above will deal with copying the quarantined items to the analysis destination without verification if the same file was previously quarantined/analysed...

the encryption what software are you considering for this?

Author

Commented:
The encryption software is from an AV product called qdecrypt which
encrypts infected files to make them harmless.

Yes, I'm looking at Qlemo scripts but just posted an update: if only
Qlemo's script track for the last date/time the script last stop/went
down, that will be perfect
Distinguished Expert 2017

Commented:
You could add logging events that would write out to a file or a DB that the script ran, and finished......

In the above script echo $(date "%b-%d-%Y %H:%M:%s") started/stopped >> record_file

.....
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Or is there something you could add to the script that
will detect an "exit" or the script being killed like
(in the days I was doing VMS DCL scripting):

on error perform ...
on fatal_error perform ...
Distinguished Expert 2017
Commented:
In a shell script you would use trap to detect signals and act accordingly.

You need to provide more context to the conditions, do not know VMS.
Adding logic to test conditions .....
nociSoftware Engineer
Distinguished Expert 2018
Commented:
then there is the incron deamon, which can act on events like creation of a new file in a directory etc.
http://incron.aiken.cz/

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial