The officially official Devuan Forum!

You are not logged in.

#1 2022-05-29 09:04:22

SpongeBOB
Member
From: Brussels
Registered: 2022-02-07
Posts: 84  

[SOLVED] /etc/crontab and etc/cron.d

Hi everyone,

I created a shell script that I run with CRON trough

su
crontab -e

So everything is running almost smoothly.

crontab -e create the job in /var/spool/cron/crontabs/root

So not the best in my case as /var is considered as unimportant and ok to be lost...

So I rather put my cron job in /etc/crontab or etc/cron.d

I've tried to add something quite simple in those file/path (as test) without success

* * * * * root /bin/echo -e "it work" >> /home/Spongebob/Desktop/CronWork.txt 2>/home/Spongebob/Desktop/errors.txt

Any ideas why it's not working ? (errors.txt is not even generated)

Last edited by SpongeBOB (2022-05-29 09:07:38)


Linux noob, plz be kind big_smile

Offline

#2 2022-05-29 19:28:40

Marjorie
Member
From: Teignmouth, UK
Registered: 2019-06-09
Posts: 141  

Re: [SOLVED] /etc/crontab and etc/cron.d

When do you actually want this cron job to repeat?

The five * you have at the beginning are where you should put the date/time info.

minute (0-59), hour (0-23), day of month (1-31), month (1-12), day of week (0-7, Sat=6, or mon..sun).

A * is used where that position is not specified. So five * means you haven't set a time/date at all.

As an example here is the mdadm job in my /etc/cron.d/

# cron.d/mdadm -- schedules periodic redundancy checks of MD devices
#
# Copyright © martin f. krafft <madduck@madduck.net>
# distributed under the terms of the Artistic Licence 2.0
#

# By default, run at 00:57 on every Sunday, but do nothing unless the day of
# the month is less than or equal to 7. Thus, only run on the first Sunday of
# each month. crontab(5) sucks, unfortunately, in this regard; therefore this
# hack (see #380425).
# time reset on grendel to 11:57 as more likely to be awake
57 11 * * 0 root if [ -x /usr/share/mdadm/checkarray ] && [ $(date +\%d) -le 7 ]; then /usr/share/mdadm/checkarray --cron --all --idle --quiet; fi

Offline

#3 2022-05-29 20:43:18

ralph.ronnquist
Administrator
From: Clifton Hill, Victoria, AUS
Registered: 2016-11-30
Posts: 710  

Re: [SOLVED] /etc/crontab and etc/cron.d

Well, five * like that actually means "run every minute", and generally it looks fine, so it really should work fine provided that
a) the pathnames are fully correct (also in letter casing), and
b) the file does end with at least one newline.

Online

#4 2022-05-29 21:23:33

Marjorie
Member
From: Teignmouth, UK
Registered: 2019-06-09
Posts: 141  

Re: [SOLVED] /etc/crontab and etc/cron.d

I stand corrected.

Yes 5 * means 5 wildcards, so it will run whenever cron checks, which is presumably once every minute.

Last edited by Marjorie (2022-05-30 13:55:41)

Offline

#5 2022-05-30 08:19:36

SpongeBOB
Member
From: Brussels
Registered: 2022-02-07
Posts: 84  

Re: [SOLVED] /etc/crontab and etc/cron.d

ralph.ronnquist wrote:

...
b) the file does end with at least one newline.

Damn, It was simply that ! and it happen to me with something else... !

Thanks @ralph.ronnquist & Marjorie.


Linux noob, plz be kind big_smile

Offline

Board footer