Version 1 of A little demon

Updated 2002-08-16 12:26:57

Richard Suchenwirth 2002-08-16 - This little script checks periodically for the existance of a file at well-specified location ("todo"), and if it exists,

  • executes it in a sh (hence Unix only, for now)
  • deletes it
  • writes the result to another file ("done")

Very simple, but seems to work also with non-trivial tasks...

 proc every {ms body} {eval $body; after $ms [info level 0]}

 set filename /home/suchenwi/todo
 every 5000 {
        if [file exists $::filename] {
                catch {exec sh $::filename} res
                set fp [open /home/suchenwi/done w]
                puts $fp $res
                close $fp
                file delete $::filename
        }
 }

To feed this demon, I only have to type at the shell prompt

  echo "grep fff t" > ~/todo   

and 5 sec or so later, the file ~/done contains the result of this demonery...


Arts and crafts of Tcl-Tk programming