Re: mailing captured output with template text

2002-01-29 Thread Gary

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: 
> To: 
> 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 EbertManager 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]




Re: mailing captured output with template text

2002-01-28 Thread John

I think output is lost with system - maybe

my $results = `$cmd`;

Also the print is not needed before the EOF.

At Monday, 28 January 2002, "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: 
>To: 
>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]
>








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




Re: mailing captured output with template text

2002-01-28 Thread Deen Hameed


Hi Rob,

You don't need to put the system call in backticks. You could just do
$result = `some command`;
to get the output of the command stored as a multiline string in $result.

system() does not store the output of the command, only the exit status of 
the command you have called.

I don't think you need to combine both at the same time at all.

hth,
deen

On Mon, 28 Jan 2002, 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: 
> To: 
> 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
> 
> 
> 
> 
> 
> 

-- 
Deen Hameedd, Accidental Programmer [EMAIL PROTECTED]


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




Re: mailing captured output with template text

2002-01-28 Thread John W. Krahn

Rob E McCormick wrote:
> 
> Thanks for the prompt repliesmy apologies, but I'm not grasping the
> quoting problem(s) or another problem.?
> 
> I revised the code to use an @array v. $scalar.  I also noticed I left out
> the -odq option in the perldoc example, so inserted it (as docs indicate,
> controls queuing/delay )
> 
> Updated script:
> 
>  1  #!/usr/bin/perl -w
>  2  use strict;
>  3
>  4  my @results = system (`/usr/bin/df -k`);

The back-ticks (``) execute the program (/usr/bin/df -k) and return the
standard output of this program which you then try to execute with the
system function.

my @results = `/usr/bin/df -k`;  # all output to array
# OR
my $results = `/usr/bin/df -k`;  # all output to scalar


>  5
>  6  open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq")
>  7  or die "Can't fork for sendmail: $!\n";
>  8  print SENDMAIL <  9  From: 
>  10  To: 
>  11  Subject: host disk usage
>  12
>  13  host disk usage
>  14  @results
>  15  EOF
>  16  close (SENDMAIL) or warn "sendmail didn't close nicely";
> 
> Result:
> mail delivers, content is:
> 
> host disk usage
> 65280
> 
> on screen error is:
> Can't exec "Filesystemkbytesused   avail capacity  Mounted
> on
> ": No such file or directory at /opt/apps/webtrends/bin/diskusage line 4



John
-- 
use Perl;
program
fulfillment

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




RE: mailing captured output with template text

2002-01-28 Thread McCormick, Rob E

Thanks for the prompt repliesmy apologies, but I'm not grasping the
quoting problem(s) or another problem.?

I revised the code to use an @array v. $scalar.  I also noticed I left out
the -odq option in the perldoc example, so inserted it (as docs indicate,
controls queuing/delay )

Updated script:

 1  #!/usr/bin/perl -w
 2  use strict;
 3
 4  my @results = system (`/usr/bin/df -k`);
 5
 6  open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq")
 7  or die "Can't fork for sendmail: $!\n";
 8  print SENDMAIL <
 10  To: 
 11  Subject: host disk usage
 12
 13  host disk usage
 14  @results
 15  EOF
 16  close (SENDMAIL) or warn "sendmail didn't close nicely";

Result:
mail delivers, content is:

host disk usage
65280

on screen error is:
Can't exec "Filesystemkbytesused   avail capacity  Mounted
on
": No such file or directory at /opt/apps/webtrends/bin/diskusage line 4



> my @results = `/usr/bin/df -k`; # now stores all the lines of df -k
> # backticks seem to be working OK?
> 
> [snip]
> 
> #everything here is in double quotes until you see another EOF
> print SENDMAIL < From: 
> To: 
> Subject: host disk usage
> 
> host disk usage
> @results
> EOF
> 
> [snip]
> 
> 


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




RE: mailing captured output with template text

2002-01-28 Thread Nikola Janceski


my @results = `/usr/bin/df -k`; # now stores all the lines of df -k
# backticks seem to be working OK?

[snip]

#everything here is in double quotes until you see another EOF
print SENDMAIL <
To: 
Subject: host disk usage

host disk usage
@results
EOF

[snip]

-Original Message-
From: McCormick, Rob E [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 28, 2002 5:29 PM
To: perl beginners (E-mail)
Subject: mailing captured output with template text


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: 
To: 
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]



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


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