寒江——独钓

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

两个思路:

一、定时执行监控脚本

  采用centos自带的crontab根据需要定时执行status.sh脚本

  #!/bin/bash

  status=$(ps -aux | grep "rsync --daemon" | grep -v "grep" | wc -l)

  if [ $status -eq 0 ];then

    systemctl restart rsyncd.service
  else
    exit 0;
  fi

 

二、后台执行的方式

  sh status.sh &

  #!/bin/bash

  while true

  do

    ps -aux | grep "rsync --daemon" | grep -v "grep" | wc -l
    if [ $? -ne 0 ]; then
      systemctl restart rsyncd.service
    fi
    sleep 10
  done

  设置开机启动:

  echo "/bin/bash /root/status" >> /etc/rc.d/rc.local

  chmod +x /etc/rc.d/rc.local

目前大致思路就是这两种,有其他思路的还望留言讨论下!

posted on 2019-10-08 11:06  寒江——独钓  阅读(482)  评论(0编辑  收藏  举报