Perl directory watcher and sender using pscp

This perl program is use for monitoring directory, and doing upload if any matched kind of file using pscp.exe. This program is running on Win32 platform

#! perl

use warnings;
#use strict;
use feature "switch";

use Win32::OLE qw(in);
use File::Copy;

my $app_dir = "C:/EXEC_NEW";
my $raw_dir = "C:/RAW_EOS";
my $arch_npoess = "C:/ARCH_NPOESS";
my $arch_fy = "C:/ARCH_FY";

my $dest = "192.168.20.101";
my $dest_dir = "/raid/raw";
my $dest_acc = "ipopp";
my $dest_access = "*****";

my $dest_addr = "ipopp\@192.168.20.101:/raid/raw";

my $uploaded_file = "";

chdir $app_dir or die "Directory not found";

PARENT: while()
{
#check pscp
#check EOSingest

sleep(6);

if(matching_processes (qr/EOSingest/)) {
print "Retreiving RAW file, please wait ...\n";
next;
}

if (matching_processes (qr/pscp/)) {
print "Uploading $uploaded_file ...\n";
next;
}

print "reading..\n";

if ($uploaded_file eq "") {

opendir (DH, $raw_dir) || die "Cannot open directory $raw_dir: $!";

my @files = readdir(DH);
my $numbfile = @files;

if ($numbfile < 2) {
next;
}

foreach my $file (@files) {
if ($file =~ /Terra/ or $file =~ /Aqua/ or $file =~ /SNPP/) {
$uploaded_file = $file;
my @args = ("$app_dir/pscp.exe","-pw","$dest_access","$raw_dir/$uploaded_file","$dest_addr");
system(@args);
#do_upload;
} elsif ($file =~ /FY/) {
move("$raw_dir/$file","$arch_fy/$file");
}
}

closedir(DH);

} else {
move("$raw_dir/$uploaded_file","$arch_npoess/$uploaded_file");
$uploaded_file = "";
}

}

sub matching_processes {

  my $objWMI = Win32::OLE->GetObject('winmgmts://./root/cimv2');
  my $procs = $objWMI->InstancesOf('Win32_Process');

  my @hits;
  foreach my $p (in $procs) {
    if ($p->Name =~ /$_[0]/) {
    my $name = $p->Name; 

    return $name;
    }
  }
}

Komentar

Postingan populer dari blog ini

Display Image on Panel after transfered via Socket :: Java

Install and Setup VSFTPD in CentOS 6.5

Centos 6 Kambing Repo