您的位置:首页 > 运维架构 > Shell

shell脚本实现Linux进程监控

2012-08-29 14:47 351 查看
awk模式匹配语法
/正则表达式/ {匹配后的操作}

#cat shell_recorder.awk
#! /bin/bash
# shell_recorder.awk
BEGIN {
print "SHELL USAGE:"
}
/bash/{++bash}
/nologin/{++nologin}
END {
print "We have "bash" bash users."
print "We have "nologin" nologin users."
}
#awk -f shell_recorder.awk /etc/passwd
We have 4 bash users.
We have 29 nologin users.
--------------------------------------------------------------------------
也可以使用以下的方法得到同样的结果:
#cat recorder.sh
#! /bin/bash
# recorder.sh
bash=`cat /etc/passwd | grep 'bash' | wc | awk '{print $1}'`
nologin=`cat /etc/passwd | grep 'nologin' | wc | awk '{print $1}'`
echo "We have $bash bash users."
echo "We have $nologin nologin users."
# sh recorder.sh
We have 4 bash users.
We have 29 nologin users.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: