crontab 作业未在 CentOS7 上启动

crontab 作业未在 CentOS7 上启动

这是我的 CentOS7 上 root 的 crontab:

# crontab -l
# Lines below here are managed by Salt, do not edit
# SALT_CRON_IDENTIFIER:CLEANCORE
0 * * * * /var/lib/scality/cleancore/clean_core.bash --log --pattern "/var/tmp/core-\%e-\%p-\%t" --maxsize 10G --keep 3
0 18 * * */2 /root/shl/synchro_ADN_To_Scality.sh

该脚本/root/shl/synchro_ADN_To_Scality.sh昨晚没有运行:

# ls ~/log | grep synchro_ADN_To_Scality-PAR-ADN-SYN01-20230130-18H
# systemctl status crond
● crond.service - Command Scheduler
   Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2023-01-26 15:58:44 CET; 4 days ago
 Main PID: 775 (crond)
   CGroup: /system.slice/crond.service
           └─775 /usr/sbin/crond -n

Jan 26 15:58:44 my-server systemd[1]: Started Command Scheduler.
Jan 26 15:58:45 my-server crond[775]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 0% if used.)
Jan 26 15:58:45 my-server crond[775]: (CRON) INFO (running with inotify support)
Jan 30 10:32:01 my-server crond[775]: (root) RELOAD (/var/spool/cron/root)
# journalctl -u crond
-- Logs begin at Thu 2023-01-26 15:58:39 CET, end at Tue 2023-01-31 10:01:02 CET. --
Jan 26 15:58:44 my-server systemd[1]: Started Command Scheduler.
Jan 26 15:58:45 my-server crond[775]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 0% if used.)
Jan 26 15:58:45 my-server crond[775]: (CRON) INFO (running with inotify support)
Jan 30 10:32:01 my-server crond[775]: (root) RELOAD (/var/spool/cron/root)
# grep "Jan 30 18:" /var/log/cron
Jan 30 18:00:01 my-server CROND[48393]: (root) CMD (/var/lib/scality/cleancore/clean_core.bash --log --pattern "/var/tmp/core-%e-%p-%t" --maxsize 10G --keep 3)
Jan 30 18:01:01 my-server CROND[48414]: (root) CMD (run-parts /etc/cron.hourly)
Jan 30 18:01:01 my-server run-parts(/etc/cron.hourly)[48414]: starting 0anacron
Jan 30 18:01:01 my-server run-parts(/etc/cron.hourly)[48423]: finished 0anacron
Jan 30 18:01:01 my-server run-parts(/etc/cron.hourly)[48414]: starting scality-clean-event-logs
Jan 30 18:01:01 my-server run-parts(/etc/cron.hourly)[48430]: finished scality-clean-event-logs
Jan 30 18:01:01 my-server run-parts(/etc/cron.hourly)[48414]: starting scality-clean-trace-logs
Jan 30 18:01:01 my-server run-parts(/etc/cron.hourly)[48437]: finished scality-clean-trace-logs

脚本如下synchro_ADN_To_Scality.sh

#!/usr/bin/env bash

logFilePrefix=$(basename $0 .sh)
logFileSuffix=$(date +%Y%m%d-%HH%MM%S).log
echo "=> Starting <$HOME/shl/synchro_with--delete-during_PAR-ADN-SYN01.sh>, you can following this script in <$HOME/log/$logFilePrefix-PAR-ADN-SYN01-$logFileSuffix>."
$HOME/shl/synchro_with--delete-during_PAR-ADN-SYN01.sh >$HOME/log/$logFilePrefix-PAR-ADN-SYN01-$logFileSuffix 2>&1
logFileSuffix=$(basename $0 .sh)_$(date +%Y%m%d-%HH%MM%S).log
echo "=> Starting <$HOME/shl/synchro_with--delete-during_PAR-ADN-SYN02.sh>, you can following this script in <$HOME/log/$logFilePrefix-PAR-ADN-SYN02-$logFileSuffix>."
$HOME/shl/synchro_with--delete-during_PAR-ADN-SYN02.sh >$HOME/log/$logFilePrefix-PAR-ADN-SYN02-$logFileSuffix 2>&1

编辑0:

# grep -r /root/shl/synchro_ADN_To_Scality.sh /var/log/cron
# grep /root/shl/synchro_ADN_To_Scality.sh /var/spool/mail/root
#

EDIT1:我的 crontab 在上一个作业后缺少换行符。现在运行正常。

我究竟做错了什么 ?

答案1

  1. 确保 cron 运行脚本,方法是使用 grep -r '/root/shl/synchro_ADN_To_Scality.sh' /var/log/cron 查看 cron 是否运行该脚本
  2. 通过检查脚本的输出日志或来自 cron 的错误电子邮件确保脚本 synchro_ADN_To_Scality.sh 正常运行

相关内容