crond doesn't work

Issues related to applications and software problems and general support
Post Reply
rmoggia
Posts: 2
Joined: 2020/08/31 09:22:41

crond doesn't work

Post by rmoggia » 2020/09/14 10:54:01

Hi.
I need to run a script every minute.
I have followed many guides and I have done exactly what they were told to do. But it didn't get it working.
I first set up a simple command to run every minute.
This is the command:

Code: Select all

2       *       *       *       *       echo "Hello"
After I restarted the service like this:

Code: Select all

sudo systemctl restart crond.service
if I run

Code: Select all

crontab -l
I get:

Code: Select all

2       *       *       *       *       echo "Hello"
But it does not work.

This is my Centos version:

Code: Select all

centos-release-8.2-2.2004.0.1.el8.x86_64
and it is installed runs in a VM.
Any idea?
Thanks

aks
Posts: 3022
Joined: 2014/09/20 11:22:14

Re: crond doesn't work

Post by aks » 2020/09/16 18:00:39

Your time configuration is wrong. That's every 02 minute as in 01h02, 02h02 etc....

tunk
Posts: 768
Joined: 2017/02/22 15:08:17

Re: crond doesn't work

Post by tunk » 2020/09/17 10:28:28

What doesn't work?
I think a cron job runs in a limited environment without a
terminal, so your echo will not output anything to a terminal.
You could try something like this:
/bin/echo "Hello" >> /path/to/some/file
Also, I think it's recommended to use systemd timers instead.

lightman47
Posts: 1183
Joined: 2014/05/21 20:16:00
Location: Central New York, USA

Re: crond doesn't work

Post by lightman47 » 2020/09/17 10:38:34

Also, if you are editing /etc/crontab (as I do) try:

Code: Select all

sudo chmod 644 /etc/crontab
sudo restorecon /etc/crontab
sudo systemctl restart crond
I have to reset permissions because I use emacs for editing.
Remember - importing/building packages will likely "byte you in the butt" come update time, long after you'd forgotten you did that! Use repos whenever possible.

BShT
Posts: 278
Joined: 2019/10/09 12:31:40

Re: crond doesn't work

Post by BShT » 2020/09/17 11:22:09

if there something in this world that works its name is cron

cron is not windows task scheduler, cron works, cron never fails

the problem is not cron, is the environment and your command

User avatar
TrevorH
Forum Moderator
Posts: 29493
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: crond doesn't work

Post by TrevorH » 2020/09/17 17:55:19

Also read /var/log/cron and see if it is actually running your task at 2 minutes past each hour (as you told it to). It may also tell you of problems in there like a missing home directory for the user. And you never need to restart crond to get new entries recognised, if it has a problem then it's not that.
CentOS 6 will die in November 2020 - migrate sooner rather than later!
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 is dead, do not use it.
Full time Geek, part time moderator. Use the FAQ Luke

lightman47
Posts: 1183
Joined: 2014/05/21 20:16:00
Location: Central New York, USA

Re: crond doesn't work

Post by lightman47 » 2020/09/17 17:59:52

And you never need to restart crond to get new entries recognised, if it has a problem then it's not that.
Thank you. Nice to know!
Remember - importing/building packages will likely "byte you in the butt" come update time, long after you'd forgotten you did that! Use repos whenever possible.

rmoggia
Posts: 2
Joined: 2020/08/31 09:22:41

Re: crond doesn't work

Post by rmoggia » 2020/09/18 13:44:18

BShT wrote:
2020/09/17 11:22:09
if there something in this world that works its name is cron

cron is not windows task scheduler, cron works, cron never fails

the problem is not cron, is the environment and your command
You're right, I had to title the post "I can't make crond work"

BShT
Posts: 278
Joined: 2019/10/09 12:31:40

Re: crond doesn't work

Post by BShT » 2020/09/18 17:40:08

cron is headless it will never echo at your console unless you cheat its output

and use full path of everything is a good practice (OK i´m a freeBSD paranoic)

as i said cron works, look at your command and environment

Post Reply

Return to “CentOS 8 - General Support”