purl's posterous

« Back to posts
  • Viewed
    times
July 26, 2011

nohup-tee-tail-mail.pl

  • Edit
  • Delete
  • Tags
  • Autopost

#!/usr/bin/perl

use POSIX;

BEGIN{($cmd, $out, $mail, $append)=@ARGV}

my $child=fork;

die $! unless defined $child;

exit 0 if $child;

setsid;

close STDIN; #, q(<), q(/dev/null);

open STDERR, q(>&), STDERR;

open STDOUT, q(|-), qq(tee @{[$append && q(-a )]}$out|tail|mail -s $out $mail);

exec $cmd;

Tweet
  • 0 responses
  • Like
  • Comment