蒐集系統上的process,目的是為了日後評估哪些process是系統和應用程式運行所必要的,今日先透過script來收集和統計process的清單。
##########################################################
## Target:
## collect & filter uid, pid, ppid and cmd column
## from ps -ef result then export to record
##
## Date: 2013/03/27
## Ver: 1.0
## Author: Jammy Yu
##########################################################
my $chk_time = `date +%Y%m%d`;
my @process = `ps -ef | grep -v UID`;
chomp($chk_time);
open(FHD, ">> /TWSE/process/process_$chk_time.log") || die "$!\n";
foreach (@process)
{
chomp;
## $1=UID $2=PID $3=PPID $4=CMD
$_ =~ /(\w+)\s+(\d+)\s+(\d+).+?[-|pts].+?:.+?\s+(.+)/;
print FHD "$1,$2,$3,$4\n";
}
close(FHD);
open(LOG, " /TWSE/process/process_$chk_time.log") || die "$!\n";
my @cmd;
my %count;
while ( <LOG> )
{
chomp;
my($uid, $pid, $ppid, $cmd) = split(/\,/, $_);
push(@cmd, $cmd);
}
foreach (@cmd)
{
if (exists $count{$_})
{
$count{$_}++;
}
else
{
$count{$_} = 1;
}
}
foreach (keys %count)
{
print "$_ ---> $count{$_} time(s)\n";
}
close(LOG);
There is a place for Jammy to memorize things. Because Jammy is always forget something, someone, some terms, some time, some where, etc. It should be a way to rescue him out of the Hell...
2013-03-26
透過背景模式進行ITM Agent安裝
先前安裝ITM Agent至90台LPAR時,若沒有善加運用背景執行程序的方法,當安裝1台需花費10分鐘的話,90台至少就要花費900分鐘!所以透過ssh中提供的f參數時,則可將程序丟到背景執行以達到同一時間並行運行安裝程序。
#!/usr/bin/ksh
for HOST in `cat /tmp/host.lst`;
do
echo "$HOST start....."
ssh -p 2222 -f $HOST '/tmp/agent_silent_install.pl'
ExecStatus=$?
if [ $ExecStatus -eq 0 ]; then
echo "$HOST finish..." >> /tmp/itm.log
else
echo "$HOST fail..." >> /tmp/itm.log
fi
done
#!/usr/bin/ksh
for HOST in `cat /tmp/host.lst`;
do
echo "$HOST start....."
ssh -p 2222 -f $HOST '/tmp/agent_silent_install.pl'
ExecStatus=$?
if [ $ExecStatus -eq 0 ]; then
echo "$HOST finish..." >> /tmp/itm.log
else
echo "$HOST fail..." >> /tmp/itm.log
fi
done
2013-03-20
2013-03-15
程序並行運行測試
配合測試需在觀察在同個時間點並行執行15個程序,且程序中皆須要有I/O的行為,原本想使用Perl的Thread Function,但其實shell就提供好用的pipe模式,下列三個情境可參考:
一、若程序相關,用管道便可以完成
cmd1 | cmd2 |...| cmdN
二、若完全無關聯,可以用job的方式
cmd1&; cmd2& ...& cmdN&
三、用script也可以,但下列的方式僅限於兩個!
perl -e 'fork() ? `cmd1` : `cmd2`'
而這次是採用第一個情境,並透過dd來產生1GB的檔案,產生檔名的方式是利用亂數來命名,簡易的Script如下所示:
#!/usr/bin/perl
my $rand=rand 3;
`dd if=/dev/zero of="$rand"_file_1GB bs=1m count=1k`;
當執行完成後,檔案名稱很幸運都沒有重複到
訂閱:
文章 (Atom)