#!/usr/bin/tclsh # Call this with no arguments and it will only respond to standard output if # it finds anything. That's ideal for a cron job. # # Call this with "verbose" as an argument and you'll see progress as it # happens. This is good for running interactively. This is good if the script # seems to get stuck somewhere and you want to know where. # If you are running any of our custom C++ software, please add the computer’s # name to this file. See "hosts" below. This helps us find problems sooner. # Among other things, if there’s a rare bug you might get core dumps # continuously, but only every few months. It was often the case that by the # time I saw the core dump, the source code had already changed, so it was hard # to track down the bug. set verbose 0 foreach arg $argv { if {$arg == {verbose}} { set verbose 1 } } if {!$verbose} { # Since we typically run in a cron job, and we only report errors, record # some record that we ran. In a shell script we normally just touch a file # in /tmp. There's no touch command in TCL. Opening for write would be # similar. But as long as we've gone this far, why not write something # meaningful. This will tell you where we are, in case ssh is running # slowly. set status_handle [open /tmp/[file tail [info script]].status.txt w] } set hosts {zoidberg leela hermes sundance yair harvey dom \ chuck-liddell dana dice sinclair-2k daisy-mae-128k fogell \ jules becca lrrr ndnd morbo pc-load-letter y2k donbot} proc header {channel time host} { puts $channel "[clock format $time]: starting $host" flush $channel } proc one_host {host} { global verbose status_handle set time [clock seconds] if {$verbose} { header stdout $time $host } else { header $status_handle $time $host } set error [catch {exec ssh $host find ~/cpp_alert_server -name 'core.*' -exec ls -l {{}} {\;}} result] if {$error || ($result != "")} { if {!$verbose} { header stdout $time $host } if {$error} { set result "Error:\n$result" } foreach line [split $result \n] { set line " $line" puts $line if {!$verbose} { puts $status_handle $line } } } } foreach host $hosts { one_host $host } # Notice the excessive quoting. Tcl is looking at the command, then ssh, the # tcsh on the remote system. This is the minimum amount of quoting I could get # away with. #exec ssh zoidberg find ~/cpp_alert_server -name 'core.*' -exec ls -l {{}} {\;} # This is a real sample result: # -rw-------. 1 phil users 599818240 Jul 26 04:58 /home/phil/cpp_alert_server/live_server/fast_alert_search/core.16190