Multiple cron jobs using wget - php

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

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.

Want to set cron job for wordpress (Backwpup plugin)

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.

Crontab in Plesk

I'm trying to run a test script using crontab within Plesk. The php file simply emails me a message
mail('me#somewhere.com','Cron Test','Test');
My path to php is /user/bin/php
I have entered * in every field, to run the script every minute with the following command:
/usr/bin/php -q /usr/httpdocs/crontest.php
However, the script is not being run.
Can anyone help?
I'm probably missing something simple, I've never used cron before.
Any advice appreciated.
Thanks.
I would start by getting it to write to a log file. eg:
* * * * * /usr/bin/php -q /usr/httpdocs/crontest.php >> /a-location/crontest.log 2>&1
This will at least give you any obvious errors like not being able to find php etc.
I found that when using the user based cron in plesk, there are a number of issues:
first I found that you should reference the script from the virtual domain. If your script has an absolute address of /var/www/vhosts/domain.com/httpdocs/email-this.php, you should reference it as httpdocs/email-this.php in the crontab.
Second, the script has to have very particular permissions, but not sure what they "must be." apache:apache is all that ever worked for me. Even with the group write permission set, user still had to be apache... weird.
Third, the easiest way to do the testing was to edit the crontab directly instead of going back into plesk every time I needed to make a change... Edit your crontab like this:
crontab -u [filesystem-username] -e
Fourth, I could never get the crontab to write to a log file outside of httpdocs (I tried statistics/logs/cron_log every way I could think of... lol... no dice). I ended up just adding the MAILTO directive at the top of the crontab file during testing:
eg:
MAILTO=you#domain.com
## * * * * * php -q httpdocs/cron.php
Also see this if you have Plesk 10 or above: http://shaun.net/2011/09/solving-plesk-10-3-1-cron-issues/
I had to do this
/usr/local/psa/bin/server_pref -u -crontab-secure-shell "/bin/sh"
to get this (example) working: wget -O - http://www.yourdomain.com/cron.php

How can I set up cron job in my site using PHP?

I want to mail after 6 hours automatically to my user who hasn't fully completed form on my website.
Help Me
Use crontab -e to edit the cron table for your account.
In the crontab, put an entry something like...
0,10,20,30,40,50 * * * * /usr/bin/wget -O - -q http://path.to/cron.handler.php
or the equivalent
*/10 * * * * /usr/bin/wget -O - -q http://path.to/cron.handler.php
...which will run the cron handler php file every 10 minutes using wget (there are other options as well, and you may need to edit the command appropriately). (Note: you don't want to just run it every 6 hours, because then if someone happened to fill out the form right after it ran, it wouldn't have been 6 hours since they filled it out next time it runs, so you'd end up with 10-11 hour gaps.)
Then in your PHP file, find users who BOTH (a) haven't fully completed the form for at least 6 hours and (b) haven't been emailed yet. Send them an email, and mark them as having been emailed.
You will need to create the php script that does the checking and mailing, and then set the cron job like the following
/path/to/php -q /home/username/public_html/mycheckingscript.php
Obviously you will need to adjust the first path to point to your php binary, and the second path to point to the full location of your checking & mailing script.
I don't think you want to set the cron up using php. Instead write a php script and then have cron execute that script every hour or so. This would be something that is going to be dependent on your operating system.
For linux, here is the manpage for using crontab.
There is no way you can change/add a schedule on the cron job on the fly. according to my experience. because until now i did not find..

Categories