Difference between revisions of "File / Directory Change Watch"

From HyperSecurity Wiki
Jump to: navigation, search
Line 3: Line 3:
 
  # Set the directory to be monitored
 
  # Set the directory to be monitored
 
  dir="/path/to/dir"
 
  dir="/path/to/dir"
 +
 
  # Start the inotifywait command to monitor the directory
 
  # Start the inotifywait command to monitor the directory
 
  inotifywait -m -e access $dir |
 
  inotifywait -m -e access $dir |
 
  while read path action file; do
 
  while read path action file; do
 +
 
   # Print a message and the details of the event
 
   # Print a message and the details of the event
 
   echo "A process has accessed the directory: $path $action $file"
 
   echo "A process has accessed the directory: $path $action $file"
 
  done
 
  done

Revision as of 06:42, 5 January 2023

#!/bin/bash
# Set the directory to be monitored
dir="/path/to/dir"

# Start the inotifywait command to monitor the directory
inotifywait -m -e access $dir |
while read path action file; do

  # Print a message and the details of the event
  echo "A process has accessed the directory: $path $action $file"
done