You have gotten lots of suggestions about the system call etc.  So I do not
have much to say about that other than to point out that the code you have
written is not very portable (since it relies on the unix command df).  If you
want a platform independent solution there is a perl alternative to df.  Take a
look at the CPAN module Filesys::DiskFree at
http://www.perldoc.com/cpan/Filesys/DiskFree.html.  I have never used it (I
discovered it while composing this response) but I think I may start :-).  If
you are unfamiliar with CPAN and how to use it etc. take a look at
http://www.cpan.org
If you just want to know how to install a CPAN module check out:
http://www.cpan.org/modules/INSTALL.html

Regarding your question about the mail error.  I would highly recommend using
the CPAN module Mail::Mailer.  Take a look at
http://www.perldoc.com/cpan/Mail/Mailer.html for details.  It should simplify
things a little and it will give you a more platform independent solution.

        Good luck,
                        Gary



"McCormick, Rob E" wrote:

> Gang,
>
> Using 'df -k' in bash, I can get this to work acceptably:
>
> # mail the disk usage for a file system to a recipient 'uid'
> df -k /data/wrc |mailx -s 'host disk usage' [EMAIL PROTECTED]
>
> I'd like to use perl to surround the output of df -k with a simple text
> message.  I used perldoc -q mail to find the code to use sendmail, but I'd
> like to extend the sendmail example slightly.  My attempt below:
>
> ----------------------
> #!/usr/bin/perl -w
> use strict;
>
> my $results = system (`/usr/bin/df -k`);
> # backticks seem to be working OK?
>
> open(SENDMAIL, "|/usr/lib/sendmail -oi -t")
>         or die "Can't fork for sendmail: $!\n";
> print SENDMAIL <<"EOF";
> From: <uid\@host>
> To: <email_acct\@acme.com>
> Subject: host disk usage
>
> host disk usage
> print "$results\n";
> EOF
> close (SENDMAIL) or warn "sendmail didn't close nicely";
> ---------------------------
>
> The error condition that occurs: mail is created and sent, I receive it, but
> the content of the mail is:
>
> host disk usage
> print "65280
> ";
>
> Any corrections you could offer that don't involve a module?
> Or is it best to install a module?
>
> Thanks,
> Rob
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

--
Gary Ebert                            Manager Network Operations
Voice:     (301) 428-2100 X2115       Comtech Mobile Datacom Corporation
Fax:       (301) 428-1004             19540 Amaranth Drive
Mobile:    (301) 332-4930             Germantown, MD  20875-2126



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to