【问题标题】:Issue with Script脚本问题
【发布时间】:2015-09-08 08:09:00
【问题描述】:

我们有一个脚本,如果进程出现故障,它会检查并发送警报。由于某种原因,它没有为所有用户正确捕获它,也没有在所有场景中发送警报。 请提出可能是什么问题。

环境 – uatwrk1, uatwrk2, uatwrk3 ------- uatwrk100
服务器名称 - myuatserver
待查进程——amc/apache/bin/httpd

脚本是:

#!/bin/ksh
  i=1
  while (( i<=100 ))
  do
    myuser=uatwrk$i
    NoOfProcess=`ps -ef | grep -v grep | grep $myuser | grep "Amc/apache/bin/httpd" | wc -l`
    if [[ $NoOfProcess -eq 0 ]]
       then
          echo "Amc process is down, sending an alert"
          # Assume sendAlert.ksh is fine
          ./sendAlert.ksh  
    else
       echo "Amc process is running fine" >> /dev/null
    fi
  (( i+=1 ))
  done

【问题讨论】:

  • 看起来sendAlert.ksh 将尽可能快地执行 100 次,然后包装器终止。我会期待一个无限循环。
  • 使用grep -w $myuser。如果 user10 正在运行,您可能会为 user1 运行良好
  • 您希望在没有 htpd 的情况下为每个用户发出警报,还是在并非所有用户都有 httpd 进程时只发出 1 个警报?

标签: shell unix ksh


【解决方案1】:

我认为@Mahesh 已经在评论中指出了问题。
当您只想拥有一封邮件时,您可以统计运行 httpd 进程的用户数。以下命令中的反斜杠是为了避免grep -v grep

ps -ef | grep "A\mc/apache/bin/httpd" | cut -d " " -f1 | grep "^uatwrk"| sort -u | wc -l

【讨论】:

    猜你喜欢
    • 2019-03-11
    • 2011-03-18
    • 2013-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多