Skip to content

Instantly share code, notes, and snippets.

@jcable
Created February 14, 2015 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcable/c9e0d0c54fcd361f0ec7 to your computer and use it in GitHub Desktop.
Save jcable/c9e0d0c54fcd361f0ec7 to your computer and use it in GitHub Desktop.
Monitor a directory and complain if there are any entries older than a specified number of seconds
# Monitor a directory for files older than a specified number of seconds
# Usage example: tclsh monitordir.tcl \\fgbsamfvcs1n42\N42_Ex18_PremBulltoFM\bbc_minute 120
proc monitordir {path max_age} {
if {![file isdirectory $path]} {
puts stderr "$path not found or is not a directory"
exit 1
}
set files [glob -nocomplain -directory $path *]
# if the folder is empty all is OK
if {[llength $files] == 0} {
exit 0
}
set now [clock seconds]
foreach file $files {
set age [expr $now - [file mtime $file]]
if { $age > $max_age } {
puts "$file has been here for $age seconds which is too long"
exit 1
}
}
}
if {$argc != 2} {
puts "Usage: [info nameofexecutable] $argv0 DIRNAME SECONDS"
exit 1
}
set path [lindex $argv 0]
set max_age [lindex $argv 1]
monitordir $path $max_age
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment