linux 监控脚本

来源:百度知道 编辑:UC知道 时间:2024/06/14 13:05:04
请大家帮我修改下面的脚本,
#! /bin/bash
iic_user=/u/iic
tempfile=ps -ef|grep $iic_user|grep -v 'grep\|/bin/sh'|awk '{print $8}'|cut -c 17-20
for ls_name in $tempfile
do
if [ "$ls_name" != "SMSG"]
then
nohup /u/iic/smsg/bin/SMSG >nohup.out &
mail -s *@126.com "SMSG down,and up"
fi
if [ "$ls_name" != "RIDB"]
then
nohup /u/iic/ridb/bin/RIDB >nohup.out &
mail -s *@126.com "RIDB down,and up"
fi
done
rm -ef $tempfile
sleep 300
备注:我想要实现的结果,假如生成的零时文件tempfile中含有数据,我想要
对比零时文件里是否含有:SMSG、RIDB,如果没有,则启动,每个字段只对比一次,依次循环下去。
就只有这些分了,IT精英们将就下···
一楼说的没错,我测试了,就是在我判断if [ "$ls_name" != "RIDB"] 时,却执行了nohup /u/iic/smsg/bin/SMSG >nohup.out & 这条语句,我想要如果判断RIDB,就执行RIDB下面的语句块。

想了很久没想出来! 共同等待答案

楼主思路有问题

假如$tempfile取值 RIDB的时候你不是要执行一下
nohup /u/iic/smsg/bin/SMSG >nohup.out &
mail -s *@126.com "SMSG down,and up"

下面是我写的,楼主测试一下!

#! /bin/bash
iic_user=/u/iic
tempfile=(`ps -ef|grep $iic_user|grep -v 'grep\|/bin/sh'|awk '{print $8}'|cut -c 17-20`)

var=`echo ${tempfile[@]}|sed 's/ //g'`

if [ ! $var=="SMSGRIDB" -a ! $var=="SMSGRIDB" ];then
if [ ! $var=="SMSG" ];then
if [ ! $var=="RIDB" ];then
nohup /u/iic/ridb/bin/RIDB >nohup.out &
mail -s *@126.com "RIDB down,and up"
nohup /u/iic/smsg/bin/SMSG >nohup.out &
mail -s *@126.com "SMSG down,and up"
else
nohup /u/iic/smsg/bin/SMSG >nohup.out &
mail -s *@126.com "SMSG down,and up"
fi
else