先說為何AIX的專武是Perl,不是bash之類,在某專案裡R6主機在出廠時就沒安裝bash,預設的Shell Script是ksh,但對ksh實在不熟而且它看來也不強大,倒是Perl支援的算完整,後續在客戶端駐點寫過版程式、抓Log分析都靠Perl了。
my @files = glob("./*.txt");
foreach my $file (@files) {
my $log = $file . ".log";
print "gen $log ...\n";
open(my $out, '>', $log) or die "error:$!";
open(my $fh, '>', $file) or die "error:$!";
while (my $line = <$fh>) {
$line =~ s/(\d{1,3}\.)(\d{1,3}\.)(\d{1,3}\.)(\d{1,3})/x.y.z$4/g;
print $out $line;
}
close $fh;
close $out;
}
主要動作是把所在目錄下的所有txt檔遇到IP格式就遮罩,如127.0.0.1會改成x.y.z.1另存.log副檔名。
由IT人員輸入密碼,透過FTP抓當天的sql檔下來,再用sqlplus匯進Oracle
#!/usr/bin/perl
use strict;
use Net::FTP;
use POSIX qw(strftime);
use File::Copy;
print "Please input the password of DBACCOUNT:\n";
system('/usr/bin/stty', '-echo');
my $password = <>;
chomp $password;
system('/usr/bin/stty', 'echo');
system "rm *.sql *.log *.err";
my $date = strftime "%Y%m%d", localtime;
print "start version...$date\n";
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("UAT/$date" . "_UAT_V01/DB") or die "NO Folder: $@\n";
$ftp->mkdir($date); # or die "Error: $@\n";
my @files = $ftp->ls;
for my $file (@files) {
next unless ($file =~ /\.sql$/);
print "GET $file\n";
$ftp->get($file);
system "cp $file ${file}.log";
system 'echo exit | sqlplus DBACCOUNT/' . $password . '@DBSID @' . $file . " 1>>${file}.log 2>${file}.err";
$ftp->cwd($date);
$ftp->put("${file}.log");
my $size = -s "${file}.err";
$ftp->put("$date/${file}.err") if ($size > 0);
$ftp->cwd("..");
}
$ftp->quit
某天客戶希望在Server端發request到LineBot的,用java很難馬上寫出,在IBM官網取得範例還是有錯:https://www.ibm.com/docs/zh-tw/flashsystem-7x00/8.4.x?topic=api-restful-usage-examples-in-perl
#!/usr/bin/perl -w
use utf8;
use strict;
use warnings;
use HTTP::Request;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new(ssl_opts => { SSL_verify_mode => 'SSL_VERIFY_NONE' });
my $request = HTTP::Request->new('GET', "https://linebotapi.com:7443/target?name=xx");
$request->header(Content_Type => 'application/json');
my $response = $ua->request($request);
print $response->content;
上面程式碼在AIX報錯是無法識別'SSL_VERIFY_NONE',說SSL_verify_mode是一個number,而SSL_VERIFY_NONE的值就是0,所以'SSL_VERIFY_NONE'改為0就能運作了。