Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

'Best way to email edited array contents?

by Anonymous Monk
on Feb 12, 2004 at 03:19 UTC ( [id://328465]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Masters of Perl stuffs.


This is most likely a "newbie" question here. My script below used to work on solaris, but stopped working correctly right about the time I installed the most recent recommended maintenance update cluster from sun. It used to email me the contents of my pretty, edited array "@quota" using the sendmail module. Now it just emails me a blank email. For future reference, what is the best way to take the contents of an edited array, such as in this script, and send its contents via email? I tried following the recipies in Oreilly's Perl Cookbook, but I got the same results :-(

#!/usr/local/bin/perl # use Mail::Sendmail; $mailhost = "mail_server"; $fromaddress = "me@.com"; $toaddress = "me@.com"; %mail = ( From => $fromaddress, Subject => "server Quota Report", Smtp => $mailhost, To => $toaddress, ); # Define Global Variables # Percentage Quota used that triggers a warning to the user. $warnquotapct = 25; # Netapp mixed mode filer my @quota = `rsh server_name quota report -x`; #Remove the top 3 lines from the quota output (header) shift(@quota); shift(@quota); shift(@quota); foreach $line (@quota) { chomp($line); ($ignore, $user, $vol, $tree, $used, $limit, $thresh, $ignore, $ignore +, $ignore) = split(/\s+/, $line); next unless ($user); $user = lc($user); next if ($user eq "\*"); next if ($user eq "root"); next if ($user eq "builtin\\administrators"); next if ($used <= "0") || ($used eq ""); # # Below line is for server right now limit = "-" # next if ($limit eq "-") || ($limit eq ""); # Strip out the "NT_DOMAIN\" prefix to the username if it's there. $user =~ s/NT_DOMAIN\\//; $used = $used / 1000; $quota = $quota / 1000; $limit = $limit / 1000; $usedquotapct= $used / $limit *100; $remainingquota = $limit - $used; if ($usedquotapct >= $maxquotapct ) { printf ("$user\'s disk usage \= %.2f MB.\nHas %.2f MB availabl +e.\nQuota set to: %.2f MB\n\n", $used, $remainingquota, $limit); } } print("\nSending email..."); sendmail(%mail) || print "Error: $Mail::Sendmail::error\n"; print("Complete\n");

Replies are listed 'Best First'.
Re: 'Best way to email edited array contents?
by arden (Curate) on Feb 12, 2004 at 04:02 UTC
    Have you verified that your rsh command still executes and returns data? My guess is that the maintenance update has either blocked rsh or quota for the user this script runs as. Have your script output the content of @quota to someplace you can capture it to see if I'm right.

    - - Arden.

      Hi Arden. Yes, the rsh command and quota command still work.
      Thank you for the response. -Chris
Re: 'Best way to email edited array contents?
by jlongino (Parson) on Feb 12, 2004 at 06:04 UTC
    I may be overlooking something obvious here, but it looks to me like you never include any attachment/body to %mail. You include to, from, subject and smtp but nothing else.

    --Jim

      Hi Jim.
      Perhaps this is the problem. I tried using the recipe from Oreilly's Perl Cookbook, but still get the same results--an empty email:
      $mailer = Mail::Mailer->new("sendmail"); $mailer->open({ From => $fromaddress, To => $toaddress, Subject => $subject, }) or die "Can't open: $!\n"; print $mailer $body; $mailer->close();

      I apologize in advance for my ignorance, but I am not sure where to put the "print $mailer $body;" and the "$mailer->close();" lines.

      From what I read, I thought I was to put the "$mailer->close();" line at the end of the script, but I'm not sure where to put the "$body" line. I think my problem is most likely not getting a handle on my object.
      Thanks for your help/responses. -Chris

        I guess all I needed was a sprintf command joining the $body with each additional user for which quota data was collected:
        $body = $body . sprintf ("$user\'s disk usage \= %.2f MB.\nHas %.2f MB + available.\nQuota se t to: %.2f MB\n\n", $used, $remainingquota, $limit);</BOLD>

        Now I get the emailed quota data.
        Thanks for the reponses, Chris

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://328465]
Approved by kvale
Front-paged by halley
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-29 08:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found