Advertisement
Guest User

monitor home

a guest
Apr 6th, 2023
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # The folder to monitor
  4. FOLDER="$HOME"
  5.  
  6. # The log file to write changes to
  7. LOGFILE="$HOME/folder_changes.log"
  8.  
  9. # Start monitoring the folder
  10. inotifywait -m -r -e create,delete,modify,move "$FOLDER" | while read line; do
  11. # Get the timestamp
  12. timestamp=$(date +"%Y-%m-%d %H:%M:%S")
  13.  
  14. # Write the event to the log file
  15. echo "$timestamp - $line" >> "$LOGFILE"
  16. done
  17.  
  18. #Note that inotify can consume a lot of system resources if you're monitoring a large number of files, so it's a good idea #to use it judiciously and only when necessary.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement