cron stopped working

updated to php8, so screen squid stopped working, removed php8, installed back php7, now cron is not starting…
sudo systemctl status cron
● cron.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
Active: inactive (dead)

restarting just hangs there…

Hi
What are you using cron for… should be using systemd and timers to trigger jobs… don’t even use it here :wink:

As cron is now managed by systemd, I see no problem in using it. After all it is almost 50 years old now and will be very difficult to remove from all systems, habits and brains.

Hi
No cron or cronie or files in any /etc/cron.* directory installed here… systemd timers… plus I can run some tasks in seconds, not minutes :wink:

That is only part of (extensions of) cron. Thing of the system manager.

AFAIK, the user interface (the crontab tool) is still available and works as intended. Probably with systemd under the hood, but that is of no concern to the end-users.

some of the lines in crontab are:

*/12  * * * *    root     sudo sarg -x -z > /dev/null 2>&1
0     23    * *    4    ufdb    /usr/bin/sh -c "/usr/local/ufdbguard/blacklists/downloads/blacklist.sh" > /dev/null 2>&1
0     23    * *    1    ufdb    /usr/bin/sh -c "/usr/local/ufdbguard/blacklists/downloads/blacklist.sh" > /dev/null 2>&1
*/5  * * * *     root    sudo /srv/www/htdocs/screensquid/fetch.sh > /dev/null 2>&1

i am open to new ideas, how to configure timers?

Hi
Just a service for your script and a timer for when you want to run…

I have an hourly update running for some conky info;


cat conky_sysinfo.service

# /etc/systemd/system/conky_sysinfo.service
#

[Unit]
Description=Run hourly system information for conky

[Service]
LogLevelMax=1
StandardOutput=file:/dev/null
StandardError=file:/dev/null
Type=simple
ExecStart=/bin/sh -c "/data/configuration/bin/zzconky_tw"

[Install]
WantedBy=multi-user.target

cat conky_sysinfo.timer 

# /etc/systemd/system/conky_sysinfo.timer
#

[Unit]
Description=Systemd hourly timer for conky system information
After=timer-sync.target

[Timer]
OnBootSec=0min
OnCalendar=*-*-* *:00:00
Persistent=true

[Install]
WantedBy=multi-user.target

One I run every 30 seconds for frequency info…


cat conky_cpu_freq.service

# /etc/systemd/system/conky_cpu_freq.service
#

[Unit]
Description=Run check_frequency script for conky

[Service]
LogLevelMax=emerg
StandardInput=null
StandardOutput=null
StandardError=journal
Type=simple
ExecStart=/usr/bin/bash -c "/data/configuration/bin/check_frequency >/dev/null 2>&1"

[Install]
WantedBy=multi-user.target

cat conky_cpu_freq.timer

# /etc/systemd/system/conky_cpu_freq.timer
#

[Unit]
Description=Systemd timer for check_frequency script
After=timer-sync.target

[Timer]
OnBootSec=0min
OnCalendar=*:*:0,30
Persistent=true

[Install]
WantedBy=multi-user.target

hmm but how to run ,say, every ten minutes?

Hi
Have a read here: systemd.timer


OnCalendar=*:0/10

or

OnCalendar=*:0,10,20,30,40,50

Apart from Malcom’s advise to use systemd timers.
Who’s crontab is this?
And take e.g. this one:

*/12  * * * *    root     sudo sarg -x -z > /dev/null 2>&1

whre apparently

root     sudo sarg -x -z > /dev/null 2>&1

is the command to be executed???
It is of course possible you have a command ‘root’, but it is not on my system.

It looks all very strange to me.

Have you tried “man 5 crontab”?

Hi
sarg - Squid Analysis Report Generator

-x Writes debug messages to stdout-z Writes process messages to stdout

Please re-read the command. It is NOT sarg, it is root.

Hi
The root user is running sudo sarg (to switch to squid user?), timers/services make much more sense :wink:

Where did you read that? in man 5 crontab?
There are 6 fields in a crontab entry. The first five are for the timing. The rest is the command to be executed. There is not such a thing as a username field.

And when the OP does not have a correct command, it will never run, using cron, systemd timer or what ever.

what can i write? thank you very much! timers work perfectly…
but i would like to fix the cron problem, seems like a bug to me…
root is just the user running the command… i have almost never used crontab -e… i just edit crontab directly…
but the content of it is not much of the matter as uninstalling cronie and reinstalling puts the default crontab and with it,
cron still does not start.
sarg better work with cron as it had scripts installed in cron daily, weekly and monthly.

And why do you think that you can put a username there? Did you read

man 5 crontab

as @avidjaar suggested?
As it is, it will most probably write to stdout

If 'root' is not a typo you can use command-not-found to lookup the package that contains it, like this:
    cnf root

But as you send all output to /dev/null, you will never see this.

The user that executes your crontab entry is the user that owns the crontab. I asked you who’s crontab it is, you did not answer >:(.

You should always use

crontab -e

else things will not all go as expected.

Hi
Just check what timers are running, (systemctl list-timers) you can just hook into one of those, else just check the scripts running an move to timers/services…

thanks for the advice… i had just enabled the .service services and then noticed that they only ran once… since i enabled the timers, things are awesome, this new method even allows a service to run from a non root user…
here is my give back, perhaps you don’t know about yet:
check this:

sudo /sbin/sysctl -w vm.drop_caches=3 
sudo /bin/sync && /bin/echo 3 | sudo /usr/bin/tee /proc/sys/vm/drop_caches