#!/bin/bash
date=`date +%Y-%m-%d_%H:%M:%S`
name=`'hostname'`
nwip=`ifconfig|grep 'inet '|grep -v '127.0'|xargs|awk -F '[ :]' '{print $2}'`
#记录日志文件
LOG_FILE="autostart.log"
#系统时间
curtime=$(date "+%Y-%m-%d %H:%M:%S")
#检测进程
pnhttp=`ps -ef |grep "jiankong_CPU_NC.sh" |grep -v "grep"|wc -l`
 
if [ $pnhttp -eq 0 ]; then
        echo "$curtime 系统检测到监控服务器cpu内存硬盘脚本,已挂掉" >> /opt/sh/jiankong/autostart.log;
        curl -s -d '' "https://api.telegram.org/bot1758755484:AAFHvuGQ8dPQlo1rEesGmtAggT6BIBt7-xw/sendMessage?chat_id=-591414316&text=""$date %0A内网IP: $nwip %0A 监控脚本以GG,正在尝试重启"
 
#尝试启动监控
	    nohup /opt/sh/jiankong/jiankong_CPU_NC.sh & 
else
        echo "$curtime 系统检测到监控脚本运行正常运行正常" >> /opt/sh/jiankongautostart.log;
	    
fi

### 定时任务每两分钟执行一次    */2 * * * * root /opt/sh/jiankong/ziqi.sh    ###### 
# https://api.telegram.org/bot1758755484:AAFHvuGQ8dPQlo1rEesGmtAggT6BIBt7-xw/sendMessage?chat_id=-591414316&text=
#参考文档:  https://blog.csdn.net/tladagio/article/details/88786340
#参考文档:  https://blog.csdn.net/u014692704/article/details/97621362
#参考文档:  https://blog.csdn.net/qq_41772936/article/details/82588014
