美文网首页
ubuntu下定时任务

ubuntu下定时任务

作者: a9b854aded01 | 来源:发表于2018-11-27 09:11 被阅读0次
    //如果没安装定时器,安装定时器
    #!/bin/sh
    cron_pid=`pgrep cron`
    if [ -z "$cron_pid" ];
    then
    apt-get install cron
    service cron start
    else
     echo "[cron]"
    fi
    //写入另一个脚本,查找某进程PID,杀死这个进程
    Pwd=`pwd`//当前脚本路径
    rm -f killRemote.sh
    echo "#!/bin/sh" >>killRemote.sh
    echo "Remote_pid=\`ps -ef |  grep Remote_Server.dll | grep dotnet | grep -v grep | awk '{print \$2}'\`" >>killRemote.sh
    echo "if [ -z \"\$Remote_pid\" ];" >>killRemote.sh
    echo "then" >>killRemote.sh
    echo "echo \"[no pid]\"" >>killRemote.sh
    echo "else" >>killRemote.sh
    echo "cur_dateTime=\"\`date +%Y-%m-%d,%H:%m:%s\`\""  >>killRemote.sh
    echo "echo \"PID: \$Remote_pid \$cur_dateTime\" >> $Pwd/killlog.txt" >>killRemote.sh
    echo " kill -9 \$Remote_pid" >>killRemote.sh
    echo "fi" >>killRemote.sh
    chmod +x killRemote.sh
    
    //写入任务计划 每天凌晨三点执行
    #echo "0 3 * * *  sh pwd/killRemote.sh" >> /var/spool/cron/root
    echo "0 3 * * *  root sh $Pwd/killRemote.sh" >> /etc/crontab
    #echo "*/1 * * * * root hostname >> $Pwd/killlog.txt" >> /etc/crontab
    #crontab -l > conf && echo "0 3 * * * sh $Pwd/killRemote.sh" >> conf && crontab conf && rm -f conf
    service cron restart
    

    相关文章

      网友评论

          本文标题:ubuntu下定时任务

          本文链接:https://www.haomeiwen.com/subject/riwtxqtx.html