在AIX上運行Java,常用crontab設定排程Perl監控運作中的系統,監控用監控哪些?
#!/usr/bin/perl
my $flag = `ps -ef | grep -v grep | grep -c batch.jar`;
chomp $flag;
unless ($flag eq "0") {
print "Running Batch...\n";
my $last = (stat("/opt/batch/logs/batch.log"))[9];
my $now = time();
print "$now - $last = " . ($now - $last) . "\n";
if ($now - $last > 3 * 60 * 1000) {
print "Batch is blocking...\n";
system "./stop.sh; nohup ./runBatch.sh >/dev/null 2>&1 &"
#print "Restarting Batch ...\n";
#system "nohup ./runBatch.sh >/dev/null 2>&1 &";
}
} else {
# print "Starting Batch...\n";
system "nohup ./runBatch.sh >/dev/null 2>&1 &";
}
另外會有一支Perl用於過版新版Java程式,會呼叫上述的監控程式。
會連上FTP抓新版jar下來,並備份舊版,然後重啟系統。
#!/usr/bin/perl
use Net::FTP;
my $HOST = "1.1.1.1";
my $ftp = Net::FTP->new($HOST) or die "Can't connect: $@\n";
$ftp->login("ftpuser", "ftppwd") or die "Can't login by ftpuser: $@\n";
$ftp->cwd("UAT1/output") or die "NO Folder: $@\n";
$ftp->binary;
system "./stop.sh";
if (defined($ftp->size("batch.jar"))) {
system "mv batch.jar batch-old.jar";
$ftp->get("batch.jar");
}
$ftp->quit;
system "./runBth.pl";