Yii and cron jobs - php

I have created a Yii command that needs to be run every month. If I go to my protected folder and run the command manually:
protected/yiic ganadores
It works fine. I have tried to add the following command line to etc/cron.hourly and etc/crontab with no success:
/usr/bin/php5 /var/www/path/to/project/protected/yiic ganadores (etc/cron.hourly/ganadores)
0 0 1 * * root /usr/bin/php5 /var/www/path/to/project/protected/yiic ganadores
(etc/crontab)
If I run the file ganadores inside etc/cron.hourly manually, it's working also.
What am I missing here?
Edit: Finally got it solved. I had some extra spaces in the cron line. Used tab instead spaces and it started working..

This is how I run my Yii cron jobs (in the root crontab file):
45 23 * * * sudo -u www-data php /path/to/yii/app/protected/console.php mycommand
Basically just regular crontab syntax, but I am running console.php instead of yiic, and I am setting the user to Apache (www-data) so the permissions are correct for my script. I am not sure why yours isn't working, but hopefully looking at mine will help you out. :)

Related

Cron is setup correct (I think) but is not running

I have set some commands in my crontab, but it seems like they are not executed.
PHP version is 7+
CentOS 7
This is my list when I run "crontab -u username -l"
45 0 * * * username /usr/bin/php /var/www/production/site/scripts/process1.php
*/2 * * * * username /usr/bin/php /var/www/production/site/scripts/process2.php
25 * * * * username /usr/bin/php /var/www/production/api/scripts/process3.php
username is an existing user and has rights to the PHP files. Same results when I use the root user.
When I run "Which php" I get the result below:
/usr/bin/php
So that seems to be OK too.
/var/log/cron shows me lines like this, so it appears to be called
CROND[29053]: (username) CMD (username /usr/bin/php /var/www/production/site/scripts/process1.php)
When I run the commands manually all works well, so the processx.php files seem to be OK.
I am running out of ideas... Can anybody point me to the right direction to tackle my (probably silly) mistake?
Alright, it is working... Still not 100% sure why it was not before.
But this is what I changed:
removed the processes with the command "crontab -e" and deleted the 3 commands there.
Then:
nano /etc/crontab
Added the commands there (with the right user to execute them) e voila!
Difference was that I used /etc/crontab directly and not using crontab -e.
Although I am now still curious why this is working and my first attempt through crontab -e is not... So, if anybody knows why, please let me know!

Crontab suddenly stop working on server?

I have some crontab set on server on linux platform.Before that 2 days all the cron was running.I dont know what happen with crontab that they are not working now.
All the cron was running before and i have added a new crontab after that they are not running may be this is the problem or is there other problem with that.
I have check ther permission but that is ok with.
New cron i have add look like that:
*/15 * * * * php myproject/sendmail.php
30 5 * * * php myproject/sendmailOnDiscount.php
* */1 * * * php myproject/sendInvitaion.php
The last one have added and before that other was running well.
After adding crontab sendInvitation.php crontab has stop working.
Could any one tell me why crontab is not working now.(All the crontab has stop working)
Maybe it is off, you can turn it on with this command
service crond start
Mostly this problem occurs due to script file permission and ownership of script files. The same problem was faced by me. I found that my script owner was not a super user e.g. root.
So, you have to set the permission and ownership of your scrip as super user. Find below.
First of all edit your crontab as super user.(in RHEL like below)
[abc#host] crontab -e
and save crontab :wq!
Now set permission for script
[abc#host] chmod +x script.sh
[abc#host] chown root:root script.sh
Now restart your crontab.(in RHEL like below)
[abc#host] /etc/init.d/crond restart

Run PHP script with CRON

I try to run PHP scripts on my debian server, everyday at midnight & 1 minute.
So I created the crontab file in admin, with
crontab -e
who seems to be in
/tmp/crontab.ky3Q3F/crontab
And I put the line
01 00 * * * /usr/bin/php5 /var/www/MySite/cronTB.php
Bellow the comments.
The goal is to run cronTB.php (with PHP) everyday at 0h01.
Is my syntax correct ?
Is the correct file to edit, to the correct path ?
Is the CRON daemon still runing after I run it with:
/etc/init.d/cron start
even if I close the ssh connexion ?
Thanks for help

Need to edit root crontab jobs from webinterface??

I want to edit the crontab of root from the web interface. I have Apache and PHP installed on my Ubuntu. If there is any permissions required please also mention that.
I want to edit the crontab of root. I have some jobs running in that crontab. One of my projects wants me to change the running jobs Time from web interface.
So please tell me how can I access the crontab of root and edit it.
permission problems: solve those by allowing www-data to run the appropriate commands via sudo.
run crontab -u root -l to get the current crontab, edit it with php string manipulation code of your liking and intall it with crontab -u root $FILE. i recommend to place markers in the file to make it easier to find the correct places to edit like so:
# Edit this file to introduce tasks to be run by cron.
# ...
# m h dom mon dow command
0 14 27 * * backupmails-monthly.sh
0 14 * * 5 backupmails-weekly.sh
# MARKER_EDIT_HERE_START
0 14 27 * * job_to_edit.sh
# MARKER_EDIT_HERE_END
a better solution if jobs run regularly: don't put them in the crontab but in /etc/cron/cron.{hourly,daily}.
if you have access to the console, you should install webmin for web management interface of the server
http://www.webmin.com/
These days there are tools like
chronos (depends on apache, has a dockerfile)
luigi from spotify
minicron
More options found at the github topic: cron

Cronjob php script not working

I'm trying to set a cronjob to run every 20 minutes.
This works manually:
php /srv/www/mysite.co.uk/public_html/PP/Make_XML.php LONDON
I tried to use "crontab -e" and set it even to every 20 minutes with:
*/20 * * * * php /srv/www/mysite.co.uk/public_html/PP/Make_XML.php LONDON
it was saved to /tmp/crontab.0xYhei9m/crontab
And it doesn't seem to work.
What's wrong here?
EDIT:
Current stats:
*. cron is up and running:
root 31855 1 0 08:39 ? 00:00:00 /usr/sbin/cron
*. Running "crontab -l" shows:
*/20 * * * * /usr/bin/php /srv/www/mysite.co.uk/public_html/PP/Make_XML.php
LONDON
And still no go. Again manually running the script works just fine.
is the cron daemon even running?
it was saved to /tmp/crontab.0xYhei9m/crontab
Yes - that's the file you just edited - its NOT the file crond reads to fire jobs. Crontab whould then read this file, install the updated crontab in the location where crond looks for it and notify crond it needs to process the file.
Have you checked:
crond is running?
your uid is allowed to schedule cron jobs (usually via /etc/cron.allow / /etc/cron.deny)
that the script really isn't being started by cron and failing due to a permissions error?
that the version of crond you are using support $PATH and can find the executable?
In case this is already online, try using wget instead of php, with the url instead of the path, ie.:
*/20 * * * * wget http://YOUR_IP/~YOUR_USER/PATH/Make_XML.php
or
*/20 * * * * wget http://mysite.co.uk/PP/Make_XML.php
First make sure the url works , just by opening it with a browser
Hope it helps!
Crontab doesn't know anything about PATH variable. So use absolute path to your php (/usr/bin/php for e.g.)/ You can run command which php to find your php path

Categories