计算机@linux_python_R 技术帖

Linux定时执行shell

2020-12-16  本文已影响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

上一篇 下一篇

猜你喜欢

热点阅读