gpt4 book ai didi

linux - grep 命令来计算 perl 中的警报

转载 作者:太空宇宙 更新时间:2023-11-04 12:16:01 25 4
gpt4 key购买 nike

我有以下脚本:

    # Find any connection alerts to report
for my $Alert (@Alerts)
{
print " $Alert->{type} alerts:\n";

print STDERR "Query: [\n$Alert->{query}]\n";
my $alertCur = $dbh->prepare($Alert->{query})
or die "Unable to prepare cursor for [$Alert->{query}]: $DBI::errstr\n";

$alertCur->execute()
or die " Unable to execute cursor: $DBI::errstr\n";

while (my $rec = $alertCur->fetchrow_hashref())
{
#already in alert, don't send
next if (defined $rec->{alert_id});

print $fh "Location Alert Notification: $Alert->{type} for Site $rec->{location_id} elapsedTime(D HH:MM): $rec->{diff_tm}\n";
print "Location Alert Notification: $Alert->{type} for Site $rec->{location_id} elapsedTime(D HH:MM): $rec->{diff_tm}\n";
$dbh->do ("($Alert->{alert_id}, $rec->{location_id}, $rec->{imperial_site_id}, current)") or die "Unable to insert alert: $DBI::errstr\n";
$alertCnt++;
}
}

$dbh->disconnect();

if ($alertCnt > 0)
{
print "Found <$alertCnt> alerts!\n";
}
else
{
print "No alerts found!\n"
}

print "Finished processing, elapsed seconds <" . (time() - $startTime) . ">\n";

exit(0);

我试过:

    ps -ef|grep myscript.pl|grep $alertCnt grep

返回:

    52642 117527  0 11:15 pts/63   00:00:00 grep myscript.pl

$alertCnt 是存储已发生警报数量的变量。我想计算变量 $alertCnts 给出的警报数量。什么在此处获取警报计数的命令的正确用法是什么?

最佳答案

请记住,Perl 有一个非常灵活的内置 grep 函数。您可以像这样在花括号之间嵌入任何您喜欢的 perl 语句:

#!/usr/bin/env perl

grep {
# do something with regex or whatever.
} `ps -ef` # can be any old command-line invocation

关于linux - grep 命令来计算 perl 中的警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47419684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com