Nazar Abubaker
Nazar Abubaker

Reputation: 505

Cron job isn't working

I have placed a Cron job on a page on my website. The command I have used is:

30 */1 * * */twitter/index.php

I want this page to refresh every hour starting at 12:30am (1:30am, 2:30am and so on). I have set my email so that I can receive errors and the error I get is

/bin/sh: 30: command not found

My host is "JustHost" (it does support Cron Jobs in cPanel)

The page is on:
www.DOMAINNAME.com/twitter/index.php

Thanks.

Upvotes: 0

Views: 1644

Answers (3)

Keith Thompson
Keith Thompson

Reputation: 263337

If this command:

30 */1 * * */twitter/index.php

is giving you this error:

/bin/sh: 30: command not found

then you're trying to execute it as a shell command.

To set up a cron command, you have to feed it to the crontab command. The best way to do this, IMHO, is to create a file (perhaps $HOME/.crontab) with properly formatted crontab entries, and then execute:

% crontab $HOME/.crontab

In other words, don't execute your crontab file, feed it to the crontab command.

Note also that you have to have white space between the fields. The first 5 fields specify when the command runs; the remainder is the command itself. You don't have a space between the 5th and remaining fields. Also, */1 is more simply written as just *. So this:

30 * * * * /twitter/index.php

would be the correct line to put into your crontab if you want to run /twitter/index.php at 30 minutes after each hour.

This assumes index.php is an executable file living in a directory called twitter at the root of your filesystem, which is possible but a bit odd. If it's somewhere else, you should specify the full path to the command you want to execute. Cron jobs run with a limited environment; in particular, they may not have the same $PATH you have in an interactive shell.

Upvotes: 1

GolezTrol
GolezTrol

Reputation: 116110

/twitter/index.php searches the directory named twitter in the system root. It is very unlikely that it is there. It may be the root of your domain, but it's not the root of your website's file system directory.

Instead, it should probably be something like this: /home/youraccountnumber/yourdomainname/twitter/index.php.

At least it is in my CPanel that also supports cron jobs. When I create a new cron, the part /home/myaccountnumber is already filled in. :)

CPanel also tells me:

Sample cron commands:
/usr/local/bin/php /home/*myaccount*/domains/domain.com/public_html/script.php
/usr/local/bin/curl --silent http://www.domain.com/cron.php > /dev/null
/usr/local/bin/wget -O /dev/null http://www.domain.com/cron.php

So, if you don't have this information, please contact your host to find out which exact path to use. They are likely to have documentation about the subject.

Upvotes: 1

Stephan
Stephan

Reputation: 17981

The command you should execute is the full path from root to the folder with the specific php file you want to run. Most CPanels will have the timing settings elsewhere and will create the cron expression for you. Just put the path to the file in the command field.

Upvotes: 0

Related Questions