Welcome to WebmasterWorld Guest from 100.25.214.89

Forum Moderators: phranque

Message Too Old, No Replies

cron job fail

Cron Job always falis

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

Junior Member

Top Contributors Of The Month

joined:Oct 28, 2017
posts: 50
votes: 0


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.
7:59 am on Feb 20, 2018 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11693
votes: 207


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...
8:43 am on Feb 20, 2018 (gmt 0)

Junior Member

Top Contributors Of The Month

joined:Oct 28, 2017
posts: 50
votes: 0


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
10:14 am on Feb 20, 2018 (gmt 0)

Senior Member

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

joined:Sept 25, 2005
posts:2091
votes: 370


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.
10:30 am on Feb 20, 2018 (gmt 0)

Junior Member

Top Contributors Of The Month

joined:Oct 28, 2017
posts: 50
votes: 0


@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?
11:08 am on Feb 20, 2018 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11693
votes: 207


and your syslog file?
11:21 am on Feb 20, 2018 (gmt 0)

Junior Member

Top Contributors Of The Month

joined:Oct 28, 2017
posts: 50
votes: 0


@phranque

i see 2-3hrs earlier logs but no recent log recored in syslog file. nothing related to cronjob
11:27 am on Feb 20, 2018 (gmt 0)

Junior Member

Top Contributors Of The Month

joined:Oct 28, 2017
posts: 50
votes: 0


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]

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

Senior Member

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

joined:Sept 25, 2005
posts:2091
votes: 370


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.
11:37 am on Feb 20, 2018 (gmt 0)

Junior Member

Top Contributors Of The Month

joined:Oct 28, 2017
posts: 50
votes: 0


@robzilla
Is this the correct way?
0 0 * * * /usr/bin/php -q /home/domain/public_html/schedule.php >& /dev/null
11:45 am on Feb 20, 2018 (gmt 0)

Senior Member

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

joined:Sept 25, 2005
posts:2091
votes: 370


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.
11:54 am on Feb 20, 2018 (gmt 0)

Junior Member

Top Contributors Of The Month

joined:Oct 28, 2017
posts: 50
votes: 0


yes it worked :) no output produced.

@robzilla @phranque
Thank you so much for your time and help :)
1:44 pm on Feb 20, 2018 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11693
votes: 207


@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
2:19 pm on Feb 20, 2018 (gmt 0)

Senior Member

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

joined:Sept 25, 2005
posts:2091
votes: 370


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.