On Tue, 22 Mar 2005 17:46:30 +0000, Saurabh Singhvi <[EMAIL PROTECTED]> wrote: > #!/usr/bin/perl > > foreach (`df -h|grep /dev/hda11`) { > split(); > # our $total = $_[1]; > # our $used = $_[2]; > our $free = $_[3]; > if ($free =~ /M/){ > $free=~ s/M//; > print $free."\n"; > if ($free <= 10) { > $mesg = "the space left is $free"; > print("low on space.\n"); > system('mailx','-s','"Space > low"','[EMAIL PROTECTED]','<',qq($mesg)) == 0 or die "Couldn't > mail $!"; > } > > } > } > > this isn't working....i have to press Ctrl+D to send the mail.....this > script will be cronned so i need the mail to be send > automatically......what can i do ?? alternatives???
That's because mailx expects your operating system's EOF. You really need to rewrite this using Net::SMTP, or MIME::Lite, or Mail::Mailer, or something along those lines. as a stop-gap measure, try ending $mesg with "\n.\n"; some versions of mail will accept a . on a line by itself as EOF, but I don't know how that works with STDIN in pipes. More importantly, though, if you're ever planning to expand this script, it has a fairly fatal flaw: the result of `` isn't automatically evaluated in list context. Store your system call to an array first. You also don't need to test m// before s///; if is doesn't match s/// won't do anything. And finally, you should be getting errors about non-numeric tests since you don't strip anything other than 'M'. You can ignore them, but they'll eventually get annoying. #!/usr/bin/perl use strict ; use warnings ; my @parts = `df -h|grep hda`; foreach (@parts) { (my $free = (split())[2]) =~ s/M//; if ($free <= 10){ # rewrite this part with a module from cpan my $mesg = "the space left is $free\n.\n"; system('mailx','-s','"Space low"','[EMAIL PROTECTED]', '<',qq($mesg)) == 0 or die "Couldn't mail $!"; } } HTH --jay -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>