Created
February 14, 2015 16:53
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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