Hi,
This is a production script, not homework!

The follow is a script I wrote designed to send mail messages with predefined 
attachments, as an alerts coming from Big Brother system. 
That is how it works: As soon as mail arrives from Big Brother, files named "down" & 
"up" generated by a .procmailrc file. The down & up files are trigger files that once 
exists, generate a mail massage with the predefined attachment (which are different 
for, which is specific for each server & service (there are 23 servers & 4 services). 
There is a directory tree of all servers & services. Each time down & up files 
generates in the right path respectively to the service+server damaged. 
I wrote this script for a single server+service. My problem now is how to make this 
work with multiple server+service. 

_______________________________________________________
#!/usr/bin/perl

use strict;
use warnings;
use Net::SMTP;
use MIME::Lite;

# defenitions
my $from_address = '[EMAIL PROTECTED]';
my $to_address = '[EMAIL PROTECTED]';
my $mail_host = 'post.tau.ac.il';
my $msg;
my $subject = 'sms alert';
my $message_body = "attached message";
my $trigger_down= '/Big_Brother/attachments/faxsrv/svcs/down';
my $trigger_up= '/Big_Brother/attachments/faxsrv/svcs/up';
my $attachment_down= '/Big_Brother/attachments/faxsrv/svcs/down.asc';
my $attachment_up= '/Big_Brother/attachments/faxsrv/svcs/up.asc';


# create down mail message+ attachment

if (-e $trigger_down) {
$msg = MIME::Lite->new (
  From => $from_address,
  To => $to_address,
 Subject => $subject,
  Data => $message_body,
  Type =>'TEXT',
) or die "Error creating mail message: $!\n";

$msg->attach (

  Path =>$attachment_down,
  Filename=>'down.asc',
) or die "Error adding the text message part: $!\n";

MIME::Lite->send('smtp', $mail_host, Timeout=>60);
$msg->send;
}

unlink $trigger_down;

# creating up mail message+ attachment

if (-e $trigger_up) {
$msg = MIME::Lite->new (
  From => $from_address,
  To => $to_address,
 Subject => $subject,
  Data => $message_body,
  Type =>'TEXT',
) or die "Error creating mail message: $!\n";

$msg->attach (
  Path =>$attachment_up,
  Filename=>'up.asc',
) or die "Error adding the text message part: $!\n";

MIME::Lite->send('smtp', $mail_host, Timeout=>60);
$msg->send;
}
unlink $trigger_up;

____________________________________________________________

used file::find module with this code peace :


@ARGV = qw(/Big_Brother/attachments) unless @ARGV;
use File::Find;
#open DOWN > @down;
find sub { print $File::Find::name, -f && '*', "\n"
}, @ARGV;

this marked all files  with a * at the end. How do I put those paths I find to an 
array, so I can match them with the rest of the script?




?Ronen Kfir
System Administrator
T.A.U Computing Division
Tel: 972-3-6407416
Fax: 972-3-6405158
cellular: 972-55-405910
E-mail: [EMAIL PROTECTED]


-----Original Message-----
From: R. Joseph Newton [mailto:[EMAIL PROTECTED] 
Sent: Saturday, June 21, 2003 9:29 PM
To: Ronen Kfir
Cc: [EMAIL PROTECTED]
Subject: Re: readir

Ronen Kfir wrote:

> Hi,
>
> This is not I was asking for!
> I'll explain again:
> 1.  Find all the places where a one specific file (with same name), is shown by read 
> recursively all subdir of certain directory (it is a trigger file for the rest of my 
> program). What you wrote is only the top level of the directory.
> 2. What I'm interested in are the paths of this file in the various directories. I 
> need to put each of those paths as a variable. (I think in array/hash).
> 3. then I go to each path & from there pick up another file with same name from all 
> different paths, then my program will go on.
>
> To make a long story short: I need the readdir switch (or anything else) for digging 
> into subdir, & a way to put the paths I find in array/hash.
> Am I clear enough now?
>
> P.S.
> I work on Linux,
>
>
>  Ronen Kfir

Then get to work!  Look, you are dictating first the method that must be used, and 
then demanding that we present you with some finished product to accomplish this.  
What have you tried?  Where are you stuck?

As some have pointed out, the File::Find module can do this job for you.  See if the 
mocule is installed, and install it if not.  Then do
perldoc File::Find
and use the information contained therein to solve your problem.

Unfortunately, using the module does not teach you anything about how to construct a 
well-ordered recusive system.  Is this what you are working on?  Is this the focus of 
your homework assignment?

If so, you will need to create a function which scans through a diretory seeking the 
file, and  calls itself on all subdirectories.  To do this effectively, you will have 
to be comfortable and skilled with passing values, both by value
and by reference, to functions.  How are your skills in this regard?

Please show some of the work that you are doing to accomplish this task, and you will 
get more help.

Joseph


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

Reply via email to