Create a bash script that runs and updates a log whenever a file is deleted -


I am new to sharing scripting and I have to create a script that will work on all the computers in my group at work (This is not just checking a computer). We have a spreadsheet that holds some file information, and I am working to automate the update of that spreadsheet. I already have an existing dragon script that gathers the required information and writes in the spreadsheet.

I need a script (cron job, maybe?) That gets activated at any time, a certain extension within the specified file path. The script must be placed on the filename before it is completely deleted. I do not need any information other than the name.

Do anyone have any suggestions where I should start with this? I have searched a little but have not found anything useful yet.

This will be something like this:

  for folders and files in path: if the file ends in .txt and is being deleted: save the file name < / Code>  

To delete each file .txt in some directories < Code> path or to run any of its subdirectories:

  remove inotifywait -m -e - format "% w% f" -r "path" 2> Stderr.log | Grep '\ .txt $' & gt; Logfile   

Explanation:

  • -m tells inotifywait to keep running. The first event is to exit the default

  • -e Deletion only tells the inautifewite to report on file removal incidents.

  • - Format "% w% f" only tells inotifywait to print the name of the deleted file

  • Path is the target directory to look for.

  • -r path tells the initifywait to monitor the subdirectory recursively.
  • 2> gt; Stderr.log tells the shell to save level output to a file named stderr.log . Unless things are working properly, you can ignore this file.

  • & gt; Logfile tells the shell to redirect all output to the file logfile . If you skip this part, the output will be directed to the standout and you can see it in real time because the file is destroyed.

  • Limit output to file with grep '\ .txt $' .txt extension.

    Mac OSX

    Similar programs are available for OSX. See.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -