linux - linux 中的 monitor-cpu 脚本

标签 linux bash shell unix

 1  # this script checks average cpu load for last 5 minutes
 2  # since this server has only one core the system will be fully #utilized when average cpu load values reach 1.00.
 3  # This script will send warning alert if value exceedes 0.80 so that action can be taken promptly.
 4  # finally it will display the top 10 users and their processes #with highest cpu utilization.
 5  #!/bin/bash
 6  up=$(uptime | awk '{ print$10 }'| sed 's/,$//')
 7  if($up -gt 0.80];
 8  echo "============================================" >> /tmp/load
 9  ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10 >> /tmp/load
10  mail -s "warning alert on QA server , CPU load exceedes the warning threshold" priyank.dewli@qpay.com.qa issuing-alerts@nexxuspg.com < /tmp/load
11  exit

=======================
 error after executing the script
line 12: syntax error: unexpected end of file

最佳答案

检查这一行:

if($up -gt 0.80];

我觉得你想要

if (( $(bc <<< "$up > 0.8") ))
then
    echo ...
    ps ...
    mail ...
fi

关于linux - linux 中的 monitor-cpu 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35153870/

相关文章:

linux - 在 JSON 对象中扩展表达式的问题

bash - 汇总特定用户所有权下的文件总大小

bash - 关于 bash 文件的混淆存在测试操作符

bash 脚本 : echo >> returns error "No such file or directory"

git rev-parse --git-path hooks 总是返回绝对路径

linux - Shell:在带有换行符的变量上使用 grep

linux - duplicity --exclude 选项不排除提到的目录

linux - Linux 中的 for 循环在不存在文件时将模式视为文件名

python - 允许python文件添加到不同的文件linux

Linux Bash 脚本代理变量