Link to home
Start Free TrialLog in
Avatar of Lucian Lazar
Lucian Lazar

asked on

Modify Perl script

Hello experts,
I have a perl script that does the following::
-get log files from a directory;
-zip them
-send them over smtp to a given mailbox
-redownload them from the mailbox
-crypt them using pgp
-crypted files gets pushed on ftp
-delete the original file

What i would like to do is:
-Delete the ftp sending part, instead move the files in a local given directory

Attached you will find the script.

Thank you in advance!!!!
export.pl.txt
Avatar of arnold
arnold
Flag of United States of America image

It looks as though the reason mail is used is similar to sending items via standard nail or third party to have external third party confirmation of date and time as well as possible log .....

Have not gotten too deeply in dealing whether the encryption/pgp/gpg encrypts the entire download include message heathers or just the attached file which I did not see it being striped out....

Before making changes, you shoukd find out what the business requirements are on whose basis this process was setup.

On several occasions one can see an implemented process that could be streamlined, but the streamlined process might not be sufficient for the requirement.

The possibility that all systems are managed and internal could point out that this process us similar to a company have internal transfer of items as proof.

But if there exist a process where package handling/transitions are recorded .........
Avatar of Lucian Lazar
Lucian Lazar

ASKER

thank you Arnold, the company needs to have the guarantee of the date and time the log was produced so being sent over email can guarantee that. the problem is that we want to switch from ftp storage to Amazon S3 storage so this is why we need help in modifying the script as we don't have any peel programmer in house.
Split the script transferring the handler of retrieve from mailbox, encrypt and store to s3
Existing script does what it does the same way emailing the file.
Keeping track of files it sent.
1) option ssh to s3 run the second process of retrieving the email. And storing. When successful, the file is deleted.
2)the Amazon storage resources can be mapped/mounted/accessed such that the process continues as is, with the last step of the file storage slightly altered.including httpd type of upload....or
3)backed up to s3 glacier storage.

What type of access if any isneeded to these files?
thank you, we need to the local directory because we know how to mount an existing Amazon S3 as a local drive using s3ql. so what we need is to copy the encrypted file got from email to /mnt/Amazon folder
thanks
At which point do you want it copied to the Amazon s3 space? before it is emailed or after it is retrieved??

The script is fairly commented.

I would suggest for the time being you continue the existing process while at the same time save a copy on the s3 cloud.
To limit the possibility of an issue leading to a situation where the file is lost.
well we need it to be copied to S3 after it has been retrieved. we won't keep the ftp servers as that storage will be discontinued.
thanks
On line 472 of your code after deals with two ftp uploads....
#Carico i file sul server storage 1 and 2
this is where you would add the copy to /mnt/Amazon (cloud based storage)
Since your script using different Modules, you could add another one
use File::Copy "cp"; #in your module load list ref http://perldoc.perl.org/File/Copy.html
   # Carico i file sul AMAZON storage 
    my $file_base;
    my $AMAZON_PATH='/mnt/Amazon"; # you might want to move it to the configuration part of your script
    $error=0;
    $stderr='';

    if ($log==3)
    {
        capture sub {
        $ftp=Net::FTPSSL->new($serverFTP1,
        Port => 21,
        Encryption => 'E',
            Debug => 1,
        ) or $error=1;
    } => \$stdout,\$stderr;
    }
    else
    {
    capture sub {
        $ftp=Net::FTPSSL->new($serverFTP1,
        Port => 21,
        Encryption => 'E',
        Debug => 0,
        ) or $error=1;
    } => \$stdout,\$stderr;
    }
    if (($error)&&($log>0))
    {
    dolog($dosyslog,"Errore nel collegamento al server FTPs $serverFTP1",$facility);
    }
    if ($log && $stderr)
    {
    dolog($dosyslog,$stderr,$facility);
    }

    if (!($error))
    {
    capture sub {
            $ftp->login($userFTP,$passFTP) or $error=1;
    } => \$stdout,\$stderr;
    }
    if (($error)&&($log>0))
    {
    dolog($dosyslog,"Errore nell'autenticazione sul server FTPs $serverFTP1",$facility);
    }
    if ($log && $stderr)
    {
    dolog($dosyslog,$stderr,$facility);
    }
    if ((!($error))&&($doopenssl==1))
    {
    capture sub {
            $ftp->binary or $error=1;
    } => \$stdout,\$stderr;
    }
    if (($error)&&($log>0))
    {
    dolog($dosyslog,"Errore nel settaggio del modo binario sul server FTPs $serverFTP1",$facility);
    }
    if ($log && $stderr)
    {
    dolog($dosyslog,$stderr,$facility);
    }
    opendir(DIRECTORY,"$uploaddir/server1");
    while($file_base = readdir(DIRECTORY))
    {
    if (!($error))
    {
        unless ( ($file_base eq ".") || ($file_base eq "..") )
        {
            capture sub {
            $ftp->put("$uploaddir/server1/$file_base","$file_base") or $error=1;
        } => \$stdout,\$stderr;
        if (($error)&&($log>0))
        {
                dolog($dosyslog,"Errore nell'invio del file $file_base su $serverFTP1",$facility);
        }
        if ($log && $stderr)
        {
                dolog($dosyslog,$stderr,$facility);
        }
        if ((!($error))&&($log>1))
        {
            dolog($dosyslog,"File $file_base correttamente inviato al server $serverFTP1",$facility);
        }
        # Cancello il file in locale
        if (!($error))
        {
            unlink "$uploaddir/server1/$file_base";
        }
        }
    }
    }

    closedir(DIRECTORY);

    capture sub {
    $ftp->quit;
    } => \$stdout,\$stderr;
    if ($log && $stderr)
    {
    dolog($dosyslog,$stderr,$facility);
    }

Open in new window


The other option is to handle what your current mail retrieval process does, starting at line 410
capture sub
            {
                open (FILEWRITE,">$AMAZON_PATH/$subject") or $error=1;
                print FILEWRITE $messaggio;
                close FILEWRITE;
                } => \$stdout,\$stderr;
                if (($error)&&($log>0))
            {
            dolog($dosyslog,"Errore nella scrittura del messaggio nella directory AMAZON_CLOUD dopo averlo ritirato dal server POP3s",$facility);
            }
            if ($log && $stderr)
            {
            dolog($dosyslog,$stderr,$facility);
            }

Open in new window


the second example will store the file in the $AMAZON_PATH that you would need to define at the top.
during the retrieval, it will store one for upload server1 and one in server2 and one in the amazon cloud.
...
Thank yoiu very much, i am testing it. i have only added the second option and in the configuration part i have put the storage path. Let's see if it works and i will get back to you. Thanks again!
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.