Shell 已激活超过X次的进程的通知

Shell 已激活超过X次的进程的通知,shell,scripting,Shell,Scripting,我对linux脚本非常陌生,但我正在尝试创建此脚本以添加到crontab中,以便检查用户进程是否已运行超过x个时间 #! /bin/sh #This feeds the list of process over 1 hour and strips the colons and sees #if it is over 12 hours. If so, then mails it to me. if $(( (ps exo time,pid | grep -v "00:00:" | awk '{p

我对linux脚本非常陌生,但我正在尝试创建此脚本以添加到crontab中,以便检查用户进程是否已运行超过x个时间

#! /bin/sh
#This feeds the list of process over 1 hour and strips the colons and sees 
#if it is over 12 hours. If so, then mails it to me.
if $(( (ps exo time,pid | grep -v "00:00:" | awk '{print $1}' | sed s/://g) >= 001200 )); then
    mailx -s "$(hostname) Long Process Detection" me@example.com
fi
到目前为止,它产生了一个错误,缺少一个“'),但我已经查看了很多次,没有看到任何未闭合的括号。在此方面的任何帮助都将不胜感激。错误为

"missing ')' (error token is "exo time,pid |grep -v "00:00:" | awk '{print }' | sed s/://g) >= 001200 ")"

上面的问题是通过在开括号内移动$来解决的,但它在条件计算中反馈了一个错误。(即我的示例中的000106>=000010)。

实际上,不确定您的代码,但这应该是您想要的,我希望:

#!/bin/sh
#This feeds the list of process over 1 hour and strips the colons and sees
#if it is over 12 hours. If so, then mails it to me.
for i in $(ps exo time,pid | grep -v "00:00:" | grep -v "TIME" | awk '{print $1}' | sed 's/://g');do
    if [ $i -ge 001200 ]; then
            #echo $i
            mailx -s "$(hostname) Long Process Detection" me@example.com
    fi
done

只需使用注释即可发送邮件或测试找到的值。

很难说脚本或复制粘贴中是否有错误,但if子句缺少“)”。3开,2关。啊,这是我版本中的一个错误。来自记事本和服务器的信息。我在收到错误的服务器上关闭了3次。电子邮件的内容应该是什么?如果有任何进程的运行时间超过12小时,是否希望if条件为true?最好是用户进程,而不是root进程。但我只是想在修复之前解决任何流程的问题。您的解决方案之前修复了缺失的),但在计算数值时遇到了问题。(即000106>=000010是我的样本)。邮件正文将只包括进程用户id、进程id和时间。请参阅本文:。鉴于
awk
可以做任何事
grep
sed
可以做,序列
grep…|格雷普…|啊…|sed…
相当难看;-)