LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   CRONTAB - how to change Times for hourly / daily? (https://www.linuxquestions.org/questions/linux-general-1/crontab-how-to-change-times-for-hourly-daily-4175706628/)

Peter_Zorian 01-19-2022 03:40 AM

CRONTAB - how to change Times for hourly / daily?
 
Hi there,

I hope anyone can help here :-)

I'm trying to change the times for the cronjobs daily and hourly...
hourly starts every hour at Minute 01.
And Daily at 03:17 AM.

But my crontab is empty at this time.
And anacron looks this:
###############################################################
# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22

#period in days delay in minutes job-identifier command
1 9 cron.daily nice run-parts /etc/cron.daily
7 55 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
###############################################################



When I configure a crontab, then the daily and hourly parts are startet twice at the specified time, too...?
Can anyone give me help?

-Zori-

michaelk 01-19-2022 04:27 AM

Welcome to LinuxQuestions.

Anacron runs separately from a cronjob and regardless of when the computer is powered on. A daily job can run anytime the computer is on from 0300 - 2200.

Why do you think you need to change times?

Peter_Zorian 01-19-2022 06:14 AM

Hi,

thanks for answer,

I will change the time because I'm resetting some things, for example the internetconnection.
and I will understand how the crontab works.
I'm sure this had worked. but now the times I configured in the crontab are ignored?

So this is my crontab:
#########################################
*/5 * * * * root run-parts /etc/cron.five-minute
17 * * * * root run-parts /etc/cron.hourly
25 6 * * * root run-parts /etc/cron.daily
47 6 * * 7 root run-parts /etc/cron.weekly
52 6 1 * * root run-parts /etc/cron.monthly
##########################################

and when I configure it, the hourly job stars at minute 01 and minute 17.
I will understand from where the job at minute 01 is comming from?

michaelk 01-19-2022 08:13 AM

What linux distribution / version are you running?

cronjobs only run at the specified time. If the computer is off nothing happens.

anacron jobs run regardless. If you turn on the computer at a time different than a cron scheduled time an anacron job will still run.

You have two jobs running, one from anacron and the other from /etc/crontab.

scasey 01-19-2022 08:55 AM

How are you accessing/editing the crontab?
If with crontab -e , you’re working with the user’s crontab…be that your user or root. I do all my server-side crontab maintenance as root…so su - to root and then crontab -e
There may also be entries in /etc/ crontab and maybe /etc/cron.d/* On my server, rsnapshot updated /etc/crontab

So, crontab for each user, and, maybe, system-wide crontab configs

PS. I also disabled anacron on the server…if it’s not up, I’ve got bigger problems than a missed cron job ;)

shruggy 01-19-2022 09:18 AM

Quote:

Originally Posted by michaelk (Post 6319931)
What linux distribution / version are you running?

run-parts is Debian-specific, so this must be something Debian-based.

Quote:

Originally Posted by michaelk (Post 6319931)
You have two jobs running, one from anacron and the other from /etc/crontab.

Well, anacron doesn't run hourly jobs. I think it's rather what scasey says.

Peter_Zorian 01-19-2022 09:40 AM

@scasey:

I'm running CENTOS 7.
This is an server, which is runnung 24/7.
So I think anacron isn't necessary or? Because it runs only when the computer starts...


I've only configured the /etc/crontab.
I've checked crontab for every user, inclusive root. nothing in.
And when I put an empty crontab (remove /etc/crontab and "touch /etc/crontab"), then the hourly job runs every "01 Minute" at full hour.
When I configure the /etc/crontab, the hourly jobs are running in addition to the "01 Minute", so here at Minute 17.
I've no idea where the 2nd time is comming...

Like here:
(from the /var/log/cron)
Jan 19 14:01:01 blobbm CROND[3626]: (root) CMD (run-parts /etc/cron.hourly)
Jan 19 14:17:01 blobbm CROND[4166]: (root) CMD ( run-parts /etc/cron.hourly)

scasey 01-19-2022 09:57 AM

I’m guessing the that the second (:01) run is from anacron…had double runs on my CentOS 7 server too.
I shut down (disabled) anacron and that stopped.
I don’t think it only runs at startup/boot, but I’ve not dug into it…as I said, if the server is not running I’ve got way bigger problems than missed cron jobs…
So, I took the quick (lazy) way out and disabled anacron, which made all the duplicate runs go away.

I guess my advice is to grok how anacron works…or not…;)

michaelk 01-19-2022 09:57 AM

In /etc/ there is
crontab
cron.d
cron.hourly
cron.daily
cron.weekly
cron.monthly
and
anacrontab

cron.d contains 0hourly which runs cron.hourly
01 * * * * root run-parts /etc/cron.hourly

Its cron.hourly that checks to make sure that anacron is running since anacron isn't a service and makes sure the other anacrontab jobs will run.

Peter_Zorian 01-20-2022 03:26 PM

@michaelk

Thank you, you're the best :-)

I'd never solved this.
This is exactly what I was searching for.
Here is the mysterious check for the RAID too...

Thanks so much...


All times are GMT -5. The time now is 05:46 PM.