Facing Issue with running cronjob

General support questions
Post Reply
tabkad12
Posts: 2
Joined: 2021/05/03 18:36:39

Facing Issue with running cronjob

Post by tabkad12 » 2021/05/03 18:46:54

Hi,
I am using CentOS 7 with php 7.1.3. We have a requirement to run two cron jobs for which we set it using crontab -e.

The scripts get executed and is giving results but strange issue is we are seeing lots of following errors under /var/log/cron file.

The frequency to generate these error logs is sometimes 10 mins and 20 mins.

(php) ERROR (getpwnam() failed)

The script are scheduled to run once at mid-night and the second script to run after an hour. I had tried giving the username ("root" & "nginx") by reading some post, but still the behaviour is the same.

crontab -l
0 0 * * * cd /var/www/mydomain.com/&&/usr/bin/php /var/www/mydomain.com/token.php
0 * * * * cd /var/www/mydomain.com/&&/usr/bin/php /var/www/mydomain.com/data_sync.php

# tail -f /var/log/cron
May 3 23:50:01 ip-172-31-243-235 crond[19778]: (php) ERROR (getpwnam() failed)
May 4 00:00:01 ip-172-31-243-235 crond[19778]: (php) ERROR (getpwnam() failed)
May 4 00:00:01 ip-172-31-243-235 crond[19778]: (php) ERROR (getpwnam() failed)

May 4 00:00:01 ip-172-31-243-235 CROND[24395]: (root) CMD (cd /var/www/mydomain.com/&&/usr/bin/php /var/www/mydomain.com/token.php)
May 4 00:00:01 ip-172-31-243-235 CROND[24394]: (root) CMD (cd /var/www/mydomain.com&&/usr/bin/php /var/www/mydomain.com/data_sync.php)
May 4 00:01:01 ip-172-31-243-235 CROND[24462]: (root) CMD (run-parts /etc/cron.hourly)
May 4 00:01:01 ip-172-31-243-235 run-parts(/etc/cron.hourly)[24462]: starting 0anacron
May 4 00:01:01 ip-172-31-243-235 anacron[24471]: Anacron started on 2021-05-04
May 4 00:01:01 ip-172-31-243-235 anacron[24471]: Normal exit (0 jobs run)
May 4 00:01:01 ip-172-31-243-235 run-parts(/etc/cron.hourly)[24473]: finished 0anacron


Any help why we are getting these php error logs will be highly appreciated.


Thanks in advance.....

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Facing Issue with running cronjob

Post by TrevorH » 2021/05/03 20:49:18

That looks like you have two places you are running a cron job from. One set will be located under /etc/cron.{d,daily,weekly,hourly} and jobs in files in those dirctories need 6 fields before the command to be run, the 1st 5 are the same as those used by crontab -e and the 6th field needs to name a user. That looks like the source of the 3 getpwnam errors in your log - someone has entered an entry there without the username.

It's possible that that was a previous attempt to get this to work. Jobs run from crontab -e do not need a user name and should not have one. These jobs are already per user so it's not required. The entries you show in your log for those appear to show it is working.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

tabkad12
Posts: 2
Joined: 2021/05/03 18:36:39

Re: Facing Issue with running cronjob

Post by tabkad12 » 2021/05/04 09:02:51

Hi Trevor,

Yes you were indeed bang on.

There was a scheduled job running under crontab with php script.

After modifying it, all well.

Thanks for your expert suggestion.

Post Reply