Linux定时执行shell

作者: 远方夕阳 | 来源:发表于2020-12-16 13:26 被阅读0次

定时检测进程挂了,然后重启

一、准备脚本

#!/bin/sh

#切换到目录
cd /usr/local/app
date=`date`

#查询端口占用
lsof -i:34567

# $? -ne 0 不存在 $? -eq 0存在 
if [ $? -ne 0 ]
then
    ./run.sh
    echo $date  ":=============== restart ==============="
else
    echo $date  ":=============== running =============="
fi

如果端口不存在了, 则重启服务

二、添加定时任务

Linux crontab 命令

crontab -e

每分钟执行脚本文件

* * * * * . /etc/profile;/bin/sh /usr/local/app/monitoring.sh

重启crond

service crond restart

查看当前系统登录用户的Crontab命令集合

crontab -l

相关文章

网友评论

    本文标题:Linux定时执行shell

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