#!c:\Perl\bin\perl # Program to check if the comp link files are generated in the FTP directory of STP. It will check past 1 hour files only use MIME::LITE; use Net::SMTP; use Email::Send; use Email::Send::Gmail; use Email::Simple::Creator; my ($sec,$min,$hour,$day,$month1,$yr19,@rest) = localtime(time); $year = $yr19+1900; $month = $month1+1; $leapyear = $year%4; $febcheck = "0"; if ($month < 10) { $month = "0".$month; } if ($day < 10) { $day = "0".$day; } print " Current Date is $year-$month-$day \n"; print " Current Time is $hour-$min-$sec \n"; $preverror = 0; $minp = '00'; $stp = 'vsnlmumstp'; $folder = 'stpmumbai'; errorcheck (); if ($errorlog == 1) { $fileprev = $filename; $preverror = 1; $minp = '30'; $stp = 'vsnlmumstp'; $folder = 'stpmumbai'; errorcheck (); email (); } $preverror = 0; $minp = '00'; $stp = 'vsnlndlstp'; $folder = 'stpdelhi'; errorcheck (); if ($errorlog == 1) { $fileprev = $filename; $preverror = 1; $minp = '30'; $stp = 'vsnlndlstp'; $folder = 'stpdelhi'; errorcheck (); email (); } sub errorcheck { $errorlog = 0; $start = $hour - 1; for ($i = $start; $i < $hour; $i++) { if ($i <= 9) { $hourp = "0".$i; } else { $hourp = $i; } $timecombo = $hourp.$minp; $filename =$stp."_comp-link_".$month.$day."_".$hourp.$minp.".csv"; $filepath = "\\\\192.168.10.212\\e\\$folder"; $filetocheck = "$filepath\\$filename"; print "\n Opening Dir for $filetocheck\n"; $errordir = 0; opendir(DIR, "\\\\192.168.10.212\\e\\$folder") || ($errordir = 1); if ($errordir == 1) { emaildir (); die "Not able to access remote directories \n";; } @files = grep /$filename/, readdir(DIR); closedir(DIR); if ($#files != 0) { $errorlog = 1; } } } sub emaildir { print "\n sending mail for Directory access failure \n"; $path1 = "\"d:\\data\\Comp_Link_Scripts\\Comp_Link_RECI_Transfer\""; $subject = "Alert_File transfer error for Comp Link File for stpdelhi and stpmumbai"; $email2 = 'a.gupta@company.com'; emailgmail1 (); $email2 = 'kunal.nakhawa@company.com'; emailgmail1 (); $email2 = 'ujjawal.khare@company.com'; emailgmail1 (); print "\n Mail Sent \n"; } sub emailgmail1 { my $email = Email::Simple->create( header => [ From => 'mepunetcl@gmail.com', To => $email2, Subject => $subject, ], body => 'Not able to connect to FTP server directories stpdelhi and stpmumbai, Please check (Contact a.gupta@company.com for details)', ); my $sender = Email::Send->new( { mailer => 'Gmail', mailer_args => [ username => 'mepunetcl@gmail.com', password => 'company@123', ] } ); eval { $sender->send($email) }; die "Error sending email: $@" if $@; } sub email { if (($errorlog == 1) && ($preverror == 1)) { print "\n sending mail \n"; $path1 = "\"d:\\data\\Comp_Link_Scripts\\Comp_Link_RECI_Transfer\""; $subject = "Alert_File transfer error for $folder"; $email2 = 'nldvoice.noc@company.com'; emailgmail2(); $email2 = 'a.gupta@company.com'; emailgmail2(); $email2 = 'vishal.arya@company.com'; emailgmail2(); $email2 = 'anilkumar.singh@company.com'; emailgmail2(); $email2 = 'kunal.nakhawa@company.com'; emailgmail2(); $email2 = 'ujjawal.khare@company.com'; emailgmail2(); print "\n Mail Sent \n"; } } sub emailgmail2 { my $email = Email::Simple->create( header => [ From => 'mepunetcl@gmail.com', To => $email2, Subject => $subject, ], body => "File $filename & $fileprev missing, Please check (Contact a.gupta\@company.com for details)", ); my $sender = Email::Send->new( { mailer => 'Gmail', mailer_args => [ username => 'mepunetcl@gmail.com', password => 'company@123', ] } ); eval { $sender->send($email) }; die "Error sending email: $@" if $@; }