Want to set cron job for wordpress (Backwpup plugin) - php

This is my first contact with cron jobs, so I'm sorry if my question sounds dumb.
BackWPup is for making a back up automatically after some period of time, but its own cron job does not work correctly. It starts only when I sign into wp-admin. So I decided to use the server's cron jobs, but I don't know how to. It says:
If you would use the cron job of your hoster you must point it to the
url: http://example.com/wp-cron.php
Also, I want to know how to remove a job.
Note: I have only ssh access, there is no hosting control panel. OS: CentOS.

I guess you should add the command
wget http://example.com/wp-cron.php >> /path/to/my/wp-cron.log 2>&1
to the crontab. Of course you can use any other CLI http-tool instead of wget, but it's the most simple I know and I think is sufficient here.
Call
crontab -e
then add a line like
0 * * * * wget http://example.com/wp-cron.php >> /path/to/my/wp-cron.log 2>&1
This will call this command every hour. For further information see man crontab.

Related

How use a cron job php?

I have to work with cron job and i read something about that like
* * * * * /usr/bin/wget http://blablaba/cron.php
(i know how set time m ex. run every minute).
My question is where i have to put that code?
in php index?
like:
You should put all cron jobs into crontab with
crontab -e
As far as I know it's the same for all Linux distros and Mac OS. As for Windows, just save yourself a trouble and go for Vagrant virtual machine
I usually put this command in WEBMIN.
Ask your hosting, where do you need to configure crons jobs.
For example in CPANEL:
You can't edit it with PHP directly.
You need to add new cron jobs using console command:
crontab -e
or add new files to the /etc/cron.d directory.
Best if you create a new file under /etc/cron.d directory which is where you should put your own cron jobs.

Execute PHP script in cron job

In our centos6 server. I would like to execute a php script in cron job as apache user but unfortunately it does not work.
Here is the edition of crontab (crontab -uapache -e)
24 17 * * * php /opt/test.php
and here is the source code of "test.php" file which works fine with "apache" user as owner.
<?php exec( 'touch /opt/test/test.txt');?>
I try to replace php with full path of php (/usr/local/php/bin/php) but also it doesn't work.
Automated Tasks: Cron
Cron is a time-based scheduling service in Linux / Unix-like computer operating systems. Cron job are used to schedule commands to be executed periodically.
You can setup commands or scripts, which will repeatedly run at a set time. Cron is one of the most useful tool in Linux or UNIX like operating systems. The cron service (daemon) runs in the background and constantly checks the /etc/crontab file, /etc/cron./* directories. It also checks the /var/spool/cron/ directory.
Configuring Cron Tasks
In the following example, the crontab command shown below will activate the cron tasks automatically every ten minutes:
*/10 * * * * /usr/bin/php /opt/test.php
In the above sample, the */10 * * * * represents when the task should happen. The first figure represents minutes – in this case, on every "ten" minute. The other figures represent, respectively, hour, day, month and day of the week.
* is a wildcard, meaning "every time".
Start with finding out your PHP binary by typing in command line:
whereis php
The output should be something like:
php: /usr/bin/php /etc/php.ini /etc/php.d /usr/lib64/php /usr/include/php /usr/share/php /usr/share/man/man1/php.1.gz
Specify correctly the full path in your command.
Type the following command to enter cronjob:
crontab -e
To see what you got in crontab.
EDIT 1:
To exit from vim editor without saving just click:
Shift+:
And then type q!
I had the same problem... I had to run it as a user.
00 * * * * root /usr/bin/php /var/virtual/hostname.nz/public_html/cronjob.php
You may need to run the cron job as a user with permissions to execute the PHP script. Try executing the cron job as root, using the command runuser (man runuser). Or create a system crontable and run the PHP script as an authorized user, as #Philip described.
I provide a detailed answer how to use cron in this stackoverflow post.
How to write a cron that will run a script every day at midnight?
I tried all combinations with PATHs, but don't work. Probably they are needed.
In my case, with Centos 7, a reboot or server worked.

call a php page using cron jobs in direct admin

I have a php file that sends an email and it works fine when I open the page with browser. (test.php located in root of my website) But I want the page runs automatically once a day. I found that this is done using cron jobs. I searched a lot and tested a lot of commands and configurations but none of them worked.
I was using * for all time fields assuming that it will run every minute (I didn't like to wait hours to test each configuration)
I tested following commands and many others that I don't remember ):
/usr/bin/php -q http://mysite.com/test.php
/usr/bin/home/php -q http://mysite.com/test.php
/usr/local/bin/php -q http://mysite.com/test.php
/home/myID/php -q http://mysite.com/test.php
#!/usr/local/bin/php -q http://mysite.com/test.php
#!/usr/local/bin/php -q /home/myID/mysite.com/public_html/test.php
Finally, I couldn't figure out what I am doing wrong.
the host is a shared linux host running Direct Admin.
Please tell me a simple step by step guide to set the cron job to run my php file.
thank you
You don't want to call the PHP binary if you're going to run the script via http. You want to use wget (or curl). Example:
*/5 * * * * user /usr/bin/wget http://yoursite.com/cron.html -q -O /dev/null
Where user is the OS user that runs the command.
If you don't have the privileges (shared host) to do something like that, change to use a VPS instance from some provider or use an online cronjob service like https://www.setcronjob.com/.
You could open the page using lynx the command line browser:
lynx -dump http://www.google.com/ > /dev/null
Or use a service like http://cronless.com
Update:
If you setup a cron job in your control panel and it didn't run then most probably your web host disabled it.
My advice is to use a cron job service like cronless.

Multiple cron jobs using wget

I am using Ubuntu server, and I want to do a wget cron job for just about every day of the week for different files.
I have gotten this to work for only one task, but anytime I try to do more it automatically overwrites the old one. I know how to set up times, and the format, etc; but I do not know how to do multiple wget cron jobs.
This is how I've been doing only one so far:
echo "*/10 * * * 5 wget http://XXX.XXX.XXX/files/thursday.php" | crontab -
Can anyone help me? Thanks
best to use the command line crontab function for maintaing cron jobs
crontab -e
will bring up the editor.
The default on most *nix system is vi, which is not newbie friendly, but you can change it to nano or pico with
export EDITOR=nano
and if your on a system like mine, your logged in user may not be the best user to run cron jobs as; so you may may have to use su to switch users before editing the crontab file.
looking at what you are specify doing, unless you really need to go through appache, you can just call the php file like so "php file.php" no wget needed.
*/10 * * * 5 php FULL_PATH/files/thursday.php > /dev/null 2>&1

Godaddy cron job setup for running php script

can you help me setup cron job on godaddy webhosting? I have php file that i need to run, it is located in cron subdirectory (so address is http://test.com/cron/file.php).
What do i need to write in command input field, so this file is runned?
NOTE: GoDaddy has been migrating all hosting packages over to cPanel. The itemized instructions below are for the older GoDaddy interface. The command is still the same.
At the time of this writing, on GoDaddy shared hosting, i could NOT use the following commands: ping, curl, nc, lynx
but i COULD use: wget
I successfully created a cron job using wget to load a PHP file containing a call to mail().
log into your GoDaddy account
click to expand the "Web Hosting" section and find the server in question
click the "Manage" button (it used to be labeled "Launch")
on the "Hosting Details" page in "Tools" section, click "Cron Job Manager" button
on the "Cron Job Manager" page, click "Create Cron Job" button
enter the title you want and select the frequency (1 hour is the most frequent allowed EDIT: GoDaddy has added 15-minute increments to the frequency choices.)
enter the command below (with your info):
wget http://YOUR_DOMAIN/YOUR_PATH/YOUR_PHP_FILE.php > /dev/null 2>&1
edit: as noted by Leandro, this is the method to make a cron job call a remote or local resource -- consult GoDaddy documentation if you want to call a resource locally only (which is also more secure if you're running more sensitive jobs)
in "YOUR_PHP_FILE.php" code all the actions you want to be performed and include a call to mail() (or whichever mail method you may want to use assuming you have configured that properly).
By using mail() the SMTP relay server will already be set properly in the "php.ini" file to: relay-hosting.secureserver.net -- which you can confirm using phpinfo().
php_path -q file_name_with_absolute_path
/usr/bin/php -q /home/[user name]/public_html/test.php
1: How to know your php_path?
echo exec('whereis php');
2: How to know absolute path of your file?
echo dirname(__FILE__);
Cron Setup for GoDaddy Shared Hosting Accounts using Cpanel.
*-->>Cron jobs run on GoDaddy's time zone in Arizona. Go Daddy doesn't publish this anywhere.
Example:
Run cron everyday at 1305 (1:05pm) pacific standard time.
5 14 * * * /usr/local/bin/php -q /home/username/public_html/scriptname.php
Your cron job command should look something like the following (unless your directory structure is different of course):
/web/cgi-bin/php5 "$HOME/html/sendy/scheduled.php" > /dev/null 2>&1
Regrads,
shahana
If you are using Godaddy this should solve your issue.
* * * * * /usr/local/bin/php /home/path/to/your/file.php > /dev/null
In Godaddy Linux hosting. I used this command to run cron job.
/usr/bin/php public_html/now your path
Use, for example CURL or wget or lynx.
lynx -s http://link.to/script.php
/usr/local/bin/php -q /home/[user name]/[path to the file]
Reference
You can setup cron jobs through the Hosting Control Center. Check out GoDaddy's official page here: https://www.godaddy.com/help/create-cron-jobs-3548 for a how-to on setting it up.
If you want to run a cron job in Godaddy. You can find following command, it will surely help you.
php -f /home/[user name]/[path to the file]

Categories