Score:0

crontab job did not start on CentOS7

cn flag

here is the crontab for root on my CentOS7 :

# 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

The script /root/shl/synchro_ADN_To_Scality.sh did not run last night :

# 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

And here is the synchro_ADN_To_Scality.sh script :

#!/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

EDIT0 :

# 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 : My crontab was missing a newline after the last job. It works fine now.

What am I doing wrong ?

diya avatar
la flag
As explained in the linked duplicate: fairly typical when the last entry in a crontab doesn't run: missing newline
SebMa avatar
cn flag
@diya OK, I just added a newline at the end of the crontab file and rescheduled the task for 11am (France TZ). I'll have to wait 20 minutes to check if it works.
SebMa avatar
cn flag
@diya It worked :) Do you mind converting your two comments to an answer so I can accept and upvote it ?
Score:0
cn flag
  1. Make sure that cron run script by grep -r '/root/shl/synchro_ADN_To_Scality.sh' /var/log/cron to see if cron run that script
  2. Make sure that script synchro_ADN_To_Scality.sh run properly by check output log of script or error email from cron
SebMa avatar
cn flag
Hi, thanks for your help. Please see my EDIT0.
cn flag
Look like that cron not pick script synchro_ADN_To_Scality.sh Please check if /var/log/cron is exists and try grep 'synchro_ADN_To_Scality.sh' /var/log/cron again
SebMa avatar
cn flag
`/var/log/cron` does exist. It was in fact a missing newline at the end of my `/var/spool/cron/root` file.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.