This is a sample program, to log the output and notify if required.

# Modules used
use Net::FTP;
use File::Copy;
use Net::FTP;
use Net::SMTP;

sub notify($);
my $error,$ftp;

my @t = localtime(time);
my ($rf, $td);
$t4++;
$td = (1900 + $t5) . ((length($t4)==1)?(0 . $t4):$t4) . ((length($t3)>1)?$t3:(0 . $t3)) . ((length($t2)==1)?(0 . $t2):$t2) . ((length($t1)>1)?$t1:(0 . $t1)) . ((length($t[0])>1)?$t[0]:(0 . $t[0]));
$tds = (1900 + $t5) . ((length($t4)==1)?(0 . $t4):$t4) . ((length($t3)>1)?$t3:(0 . $t3));

open(LOG,">>/usr/perl_scripts/get_filenames.log");

mark_time("$tds");
mark_time("1.Connection to the test server");
$ftp = Net::FTP->new("testserver.vago.com", Timeout => 75, Debug => 0, BlockSize => 1024);

if (!$ftp) {
return(notify("Could not connect to testserver.vago.com"));
}
else
{
print LOG "Successfull Connection to the server\n";
}


mark_time("2.Login to the testserver.vago.com");
$ftp->login("testftp","123qwe") || (return(notify("Could not login to testserver.vago.com")));
print LOG "Successfull login to the server\n";


mark_time("3.Get files from the server and then delete them");
$ftp->cwd("/home/testftp/cat/rat");
@dirlist = $ftp->ls();
foreach $file (@dirlist) {
$ftp->get($file,"/home/testftp/cat/rat/$file") || (return(notify("Could not get the files")));
notify("Got the file $file from server to the local machine\n");
print LOG "$tds $file\n";
$ftp->delete($file) || (return(notify("Could not delete $file in server")));
}

$a= "--------------------------------------------------------";
open(PLOG, ">>//usr/perl_scripts/process.log");
printf PLOG ("%-20s%20s\n", $a);
close(LOG);

######################################################################################
# Send emails
sub notify ($) {
my $error = shift;

my $smtp = Net::SMTP->new('mail.vago.com');
if (!$smtp) {
my @t = localtime(time);
my $td;
$t4++;
$td = 1900 + $t5 . "/" . ((length($t4)==1)?(0 . $t4):$t4) . "/" . ((length($t3)>1)?$t3:(0 . $t3)) . " " . ((length($t2)==1)?(0 . $t2):$t2) . ":" . ((length($t1)>1)?$t1:(0 . $t1)) . ":" . ((length($t[0])>1)?$t[0]:(0 . $t[0]));
print OUT "test.PL Could not connect to SMTP server mail.vago.com at $td\n";
close(OUT);
return(undef);
}
my $email = "test.pl: $error\n";
my $MailFrom = "test_test\@vago.com";
$smtp->mail( $MailFrom );

$smtp->recipient("sago.gara\@vago.com", { SkipBad => 1 });
$smtp->data();
$smtp->datasend("Subject: Test: FTP \n");
$smtp->datasend("\n");
$smtp->datasend( $email );
$smtp->datasend("\n");
$smtp->dataend();
$smtp->quit;

return($error)
}
####################################################################################################
# print out time stamp and message
sub mark_time ($) {
my $message = shift;
my @t = localtime(time);

$t4++;
my $runtime = 1900 + $t5 . "-" . ((length($t4)==1)?(0 . $t4):$t4) . "-" . ((length($t3)>1)?$t3:(0 . $t3)) . " " . ((length($t2)==1)?(0 . $t2):$t2) . ":" . ((length($t1)>1)?$t1:(0 . $t1)) . ":" . ((length($t[0])>1)?$t[0]:(0 . $t[0]));
open(PLOG, ">>/usr/perl_scripts/process.log") or warn("can't open log file: $!");
printf PLOG ("%-20s%20s\n", $message, $runtime);
close(PLOG);
}

In reply to Re: Get the out put when run script through remotely and locally by sago
in thread Get the out put when run script through remotely and locally by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.