sean finney on 31 Oct 2003 17:48:01 -0500 |
hey guys, over the past couple days i've thrown together a nifty little perl script to make a sysadmin's email-reading life a little easier. it's a wrapper to use around cron/at jobs that basically runs a process, captures the stdin/stdout/exit, and reports what you care about via email with a quick to grok subject header. after i get this part fully functional, i'll probably even add in regular expressions to watch for. anyway, it works reasonably well already, but i'm having trouble with catching exceptions when the call to exec (via IPC::Open3) fails due to a bad path/interpreter. i'm doing something like ... eval { $cmd_pid=open3(\*IN, \*OUT, \*ERR, @cmd); }; if($@ =~ /exec/){ print "\@ is $@\n"; $cmd_errstr = $@; $cmd_retval = "-1"; die; }; ... # code that sends email in if/else blocks if i call the script with a command that doesn't exist, calling process seems to fork, and i get two seperate emails--even though each part of the code that sends the email is in a seperate block of an if/elsif/else statement! furthermore, the file descriptors seem to get messed up and when the command fails, the stdout/stderr of @cmd get mixed up with the stdout/stderr of the calling process. i think i have this one figured out (descriptors not initialized having default values == STDIN/STDOUT) but i'm not sure. anyway, i realize this is a bit OT (yeah, yeah, i should be posting to some perl-users list), but i promise to share the script with anyone who might think it useful it when i'm done. in the meantime i think i'm just going to come up with some kind of hack that just tries to stat() the file... thanks, sean Attachment:
signature.asc
|
|