[ Please do not top-post your replies. TIA ]
Armin Garcia wrote:
Hi ...
Hello,
Well Im sorry for my late reply but here is my final script ( wrotte by me ) of solve this problem ... #!/usr/bin/perl #Modulos use MIME::Lite; use warnings; use strict; ################################################################# ################ Configuration ################################## ################################################################# #Nombre del servidor de correo revisar /etc/posfix my $mail_host='servidor.mx'; #Ruta del directorio donde se encuentran los attach del email my $attach_path="/home/user/To\-Email"; #Ruta del directorio log que CaptureHPC crea my $log_path="/home/user/To\-Email/log"; ################################################################################## ################ Funciones ################################## ################################################################################## sub SendEmailwAttach{ print "Estoy aqui .... tratando de enviar el mail\n"; my $attache= shift(@_); print "attache=$attache"; my $msg=new MIME::Lite; $msg = MIME::Lite->new( From => '[EMAIL PROTECTED]', To => '[EMAIL PROTECTED]', Cc => '[EMAIL PROTECTED]', Subject => 'Reporte de Urls Maliciosas...', Type => 'multipart/mixed' ); my $pwd=`pwd`; print $pwd,"\n";
You should probably use the Cwd module for that instead. perldoc Cwd
my @data=`./hpc-log-parser-english.sh $log_path`;
That is OK although you will get error messages and better control if you use open() readline and close() to access data from an external program.
perldoc perlopentut perldoc -f open
### Aqui coloca el texto que deseas !!!!: ### (Note that "attach" has same arguments as "new"): $msg->attach( Type =>'TEXT', Data => "@data"
perldoc -q "Why do I get weird spaces when I print an array of lines?"
) or die "Error: during put data on Attach ... $!"; chomp($attache); ### Aqui agrega el archivo que quieres: $msg->attach( Type => 'x-gzip', Path => "gzip < $attache |", ReadNow => 1, Filename => 'backup.tgz', Disposition => 'attachment' ) or die "ERROR: here in the attach ...$!"; #Enviando el Email MIME::Lite->send('smtp',$mail_host,Timeout=>60); $msg->send; print "Listoooooo ....\n"; } sub limpia_Attach{ my @something=`ls $attach_path`;
It would probably be better to use opendir(), readdir() and closedir() to do that than running an external program.
print "numero: $#something\n";
$#something is the index of the last element of @something which is *not* the number of file names in @something. You want to use @something in scalar context.
if ( @something ){ print "Tiene algo\n"; print @something,"\n"; foreach (@something){ `rm -rf $_`;
You should probably use File::Path::rmtree for that instead. perldoc File::Path
} print "ok ...\n"; }else{ print "Esta vacio\n"; } } sub Main{ my $aux; my @tmp=`ls $attach_path`;
It would probably be better to use opendir(), readdir() and closedir() to do that than running an external program.
foreach (@tmp){ if ($_ =~ /backup*/){
The * modifier affects the character 'p' so that matches 'backu' or 'backuppppp', etc. It could be more simply written as /backu/.
$aux=$_; } }
Your loop stores the *last* occurrence of a file name that matches /backu/. $aux also contains a newline at the end which you should remove here instead of in the SendEmailwAttach() subroutine. Of course you wouldn't have a trailing newline if you used opendir() and readdir() to get the list of file names.
my $file="$attach_path/$aux"; print "archivo=$file"; if ( $file ){
$file will *always* be true so this test is superfluous and the message "sorry, es un directorio, $aux\n" will *never* be printed.
print "Enviando Email w attach\n"; SendEmailwAttach($file); }else{ print "sorry, es un directorio, $aux\n"; } } Main(); limpia_Attach(); I reply and post this script if somebody sometime need help in this kind of problems, and maybe works or help some other people. Thanks all the people who reply all my latest post and give time to this problem, thanks for all
John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/