Forum Moderators: phranque

Message Too Old, No Replies

cron job fail

Cron Job always falis

         

anthonyinit 2017

5:10 am on Feb 20, 2018 (gmt 0)

5+ Year Member Top Contributors Of The Month



Hello all,

My VPS : Debian 9 + Virtualmin + PHP7.0

I'm trying to run a cron job on my server VPS
0 0 * * * /usr/bin/php -q /absolute/path/to/schedule.php

every time i start cron job i get error message
/bin/sh: 1: 0: not found


any help i can get from you all

thank you.

phranque

7:59 am on Feb 20, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



look for clues in your syslog file.
probably in /var/log/syslog but there may be a more specific log file for cron jobs in your configuration.
in some cases cron errors are emailed to an admin email.

have you tried executing the cron command from the command line?
you might learn more if you execute the command as the same user and under the same environment as cron runs...

anthonyinit 2017

8:43 am on Feb 20, 2018 (gmt 0)

5+ Year Member Top Contributors Of The Month



Ok i did run in command line and i got error
root@3210:~# 0 0 * * * /usr/bin/php -q /home/public_html/schedule.php
-bash: 0: command not found

robzilla

10:14 am on Feb 20, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The whole point of a cron job is that you don't run a command yourself, but set it up so that the cron software automatically runs it at a particular time. So you need to set that up first. What you ran above is a line that only the cron software will be able to parse; Bash does not understand it and will interpret the first part ("0") to be a reference to a command, but there's no command named "0"(zero), so you get "command not found". The actual command your cron job has to run starts with "/usr/bin/php", so if you want to test that from the command line you only enter the command "/usr/bin/php -q /home/public_html/schedule.php".

The structure of a cron job is:
[minute] [hour] [day of month] [month] [day of week] [command]

So your line, if properly set up as a cron job, will run the PHP script once a day at 0:00.

But first you have to add it to the crontab. Enter "crontab -e" on the command line to open the crontab for editing. Then press "i" to be able to edit the file. Enter your cron job on a new line, hit Esc, then enter ":wq" to save the crontab file and exit. This is assuming that vi(m) is your default text editor, if it's nano or something else the commands will differ.

anthonyinit 2017

10:30 am on Feb 20, 2018 (gmt 0)

5+ Year Member Top Contributors Of The Month



@robzilla
Thank you for your reply i follow your example here are the output...

return with <br><br><br>root@server :~#

https://ibb.co/fR1RFx
https://ibb.co/eYn0ax


Is this working correctly?

phranque

11:08 am on Feb 20, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



and your syslog file?

anthonyinit 2017

11:21 am on Feb 20, 2018 (gmt 0)

5+ Year Member Top Contributors Of The Month



@phranque

i see 2-3hrs earlier logs but no recent log recored in syslog file. nothing related to cronjob

anthonyinit 2017

11:27 am on Feb 20, 2018 (gmt 0)

5+ Year Member Top Contributors Of The Month



ok my bad i see something related to CRON


Feb 20 12:19:18 server named[902]: REFUSED unexpected RCODE resolving '141.146.158.162.in-addr.arpa/PTR/IN': 173.245.58.100#53
Feb 20 12:19:18 server named[902]: REFUSED unexpected RCODE resolving '141.146.158.162.in-addr.arpa/PTR/IN': 173.245.59.100#53
Feb 20 12:20:01 server CRON[12787]: (root) CMD (/etc/webmin/status/monitor.pl)
Feb 20 12:20:03 server named[902]: REFUSED unexpected RCODE resolving '110.221.162.108.in-addr.arpa/PTR/IN': 173.245.58.100#53
Feb 20 12:20:03 server named[902]: REFUSED unexpected RCODE resolving '110.221.162.108.in-addr.arpa/PTR/IN': 173.245.59.100#53
Feb 20 12:20:03 server named[902]: REFUSED unexpected RCODE resolving '110.221.162.108.in-addr.arpa/PTR/IN': 173.245.58.100#53
Feb 20 12:20:03 server named[902]: REFUSED unexpected RCODE resolving '110.221.162.108.in-addr.arpa/PTR/IN': 173.245.59.100#53
Feb 20 12:20:52 server named[902]: REFUSED unexpected RCODE resolving '194.221.162.108.in-addr.arpa/PTR/IN': 173.245.58.100#53
Feb 20 12:20:52 server named[902]: REFUSED unexpected RCODE resolving '194.221.162.108.in-addr.arpa/PTR/IN': 173.245.59.100#53
Feb 20 12:20:52 server named[902]: REFUSED unexpected RCODE resolving '194.221.162.108.in-addr.arpa/PTR/IN': 173.245.58.100#53
Feb 20 12:20:52 server named[902]: REFUSED unexpected RCODE resolving '194.221.162.108.in-addr.arpa/PTR/IN': 173.245.59.100#53
Feb 20 12:22:58 server named[902]: REFUSED unexpected RCODE resolving '212.221.162.108.in-addr.arpa/PTR/IN': 173.245.58.100#53
Feb 20 12:22:58 server named[902]: REFUSED unexpected RCODE resolving '212.221.162.108.in-addr.arpa/PTR/IN': 173.245.59.100#53
Feb 20 12:22:58 server named[902]: REFUSED unexpected RCODE resolving '212.221.162.108.in-addr.arpa/PTR/IN': 173.245.59.100#53
Feb 20 12:22:58 server named[902]: REFUSED unexpected RCODE resolving '212.221.162.108.in-addr.arpa/PTR/IN': 173.245.58.100#53
Feb 20 12:23:45 server systemd[1]: Started Session 347 of user root.

[edited by: anthonyinit_2017 at 11:29 am (utc) on Feb 20, 2018]

robzilla

11:27 am on Feb 20, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If your schedule.php scripts outputs "<br><br><br>" then yes that is working as intended. However, any output generated by a cron job may be logged and/or e-mailed so if you don't need that output for further processing, I would make sure the PHP script doesn't output anything at all, and/or send all output to /dev/null (trash can basically) by adding " &> /dev/null" to the end of the cron job line.

@phranque: it seems all he did was run the cron line straight from bash, there was no cron job.

anthonyinit 2017

11:37 am on Feb 20, 2018 (gmt 0)

5+ Year Member Top Contributors Of The Month



@robzilla
Is this the correct way?
0 0 * * * /usr/bin/php -q /home/domain/public_html/schedule.php >& /dev/null

robzilla

11:45 am on Feb 20, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



No, it's "&>" not ">&". Other than that, yes that looks fine.

Test it by running the command part from the command line.

Running this...
/usr/bin/php -q /home/domain/public_html/schedule.php &> /dev/null

...should not produce any output.

anthonyinit 2017

11:54 am on Feb 20, 2018 (gmt 0)

5+ Year Member Top Contributors Of The Month



yes it worked :) no output produced.

@robzilla @phranque
Thank you so much for your time and help :)

phranque

1:44 pm on Feb 20, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



@phranque: it seems all he did was run the cron line straight from bash, there was no cron job.

i was referring to logged messages relevant to the OP:
every time i start cron job i get error message
/bin/sh: 1: 0: not found

robzilla

2:19 pm on Feb 20, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I know. But the OP error message also suggests he ran the cron line straight from the shell (where 0 is taken for a command), and that wouldn't be logged anywhere as far as I'm aware, or if it would the error message would be the same ("command not found").

Glad you got it working in the end.