【发布时间】:2011-01-21 23:09:01
【问题描述】:
有没有更好的方法以编程方式使用 perl 来跟踪 unix 进程的时间(开始时间、结束时间)?
例如,我有一个使用 system() 启动 unix 命令的 perl 脚本。我在 system() 之前和之后打印时间戳。
我的开始时间和结束时间的日志是一样的。我确定该过程何时完成只需几分钟,所以它不准确。
到目前为止,这是我的代码:
my $dt = strftime('%Y%m%d', localtime(time));
my $dt2 = strftime('%Y%m%d-%H:%M:%S', localtime(time));
my @tbls = qx(mysql -u foo -pmypw --database $dbsrc -h $node -ss -e "show tables");
open (CRLOG, ">dump-$dt.log") || die "cannot append";
foreach my $tbls (@tbls)
{
chomp $tbls;
print CRLOG "TIME START => $dt2\n";
my $crfile = qq{mysql -u foo -pmypw --database $dbsrc -h $node.test.com -ss -e "SELECT 'a','b','c' UNION SELECT 1,2,3 FROM $tbls"| tr "\t" ",">$node-$tbls.$dt.csv}; system($crfile);
print CRLOG "COMMAND => $crfile\n";
print CRLOG "TIME END => $dt2\n";
};
close (CRLOG);
【问题讨论】:
-
您在调用命令之前获取
$dt2,而不是之后。
标签: perl