centos crond执行shell无反应

johopig 2019-08-31 11:51:58
首先restart_mysql.sh文件如下

# !/bin/sh
pidof mysqld >/dev/null
if [ $? -eq 0 ]
then
echo "running...">> ./mysql_log.txt
else
echo " mysql server was stopped">> ./mysql_log.txt
service mysql start
fi

crontab -e 进入编辑如下

*/2 * * * * /var/spool/cron/restart_mysql.sh

接着

service crond restart
两分钟后去看 mysql_log.txt 是空的,
但是直接在该目录下 ./restart_mysql.sh之后去查看mysql_log.txt,能看到增加了一条信息。。。
...全文
185 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
johopig 2019-09-03
  • 打赏
  • 举报
回复
1使用绝对路径 2. shell脚本第一行直接 cd到所操作的目录
johopig 2019-08-31
  • 打赏
  • 举报
回复
crond 配置如下

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

19,612

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧