So i have this php function path in codeigniter which I am trying to run through cron job in ubuntu. But whatever I have tried it is not working. The command I have tried so far
* * * * * /usr/bin/php http://localhost/QAPIv2/updateTestData
But it is not executing. I am using codeigniter
To elaborate on Rohan's answer, you run the functions like php index.php controller function. So, for example, to run your script every Tuesday at 8:31AM, your crontab entry should look like :
31 08 * * 2 cd /path/to/codeigniter; /usr/bin/php index.php QAPIv2 updateTestData;
Try this:
*/1 * * * * /usr/bin/php /var/www/html/YOUR PROJECT FOLDER NAME/index.php YOUR FUNCTION NAME > /dev/null 2>&1
First number is time for cron.In function name you should give the controller function name which you want to load in cron.
Please call the function from the command line.
$ cd /path/to/project;
$ php index.php controller function
Please change the controller and function according to your code.
Related
I hava a php-email (phpmailer 5.2.14) script which work fine when I run it in bash:
pi#schnickschnack: php /var/www/html/email.php
when i run this script with cron (sudo crontab -e):
*/1 * * * * root php /var/www/html/email.php
syslog says...
Jan 22 08:53:01 Schnickschnack CRON[4482]: (root) CMD (root php /var/www/html/email.php)
...but I get no mail.
I have another php-script which works fine with crontab. this script inserts values from phpmodbus into a mysql-db...
does anyone have a hint why the mail-script does not work with cron?
try
* * * * * php /var/www/html/email.php
otherwise, cron tries to execute the command "root", which is not a command.
As you are running by cron, all your usual $PATH and ENV are not available.
So CRON has no idea where to find "php".
Depending on your install - determine location of the PHP bin:
which php
use the resulting path in your cronjob. eg:
*/1 * * * * /bin/php /var/www/html/email.php
** Unless intended, dont leave the email.php script where it could be run "unintentionally" by anyone simple hitting the webserver. email.php is certainly on script kiddies hit list.
I've been at this for hours and have tried everything with no luck.
I am basically trying to run this http://docs.phpservermonitor.org/en/latest/install.html#setting-up-a-cronjob
I'm using MAMP and my localhost is a custom folder under User/username/localhost/servercheck
What I've tried so far is.
crontab -e
added */1 * * * * root /usr/bin/php /Users/clientsupport1/localhost/servercheck/cron/status.cron.php
And when I type crontab -l to see if its loaded I see the following.
*/1 * * * * root /usr/bin/php /Users/clientsupport1/localhost/servercheck/cron/status.cron.php
But the script does not run. I even tried a simple script that writes to a file. Still nothing. For some reason the cron job doesn't execute. Any ideas?
You need to call MAMP’s PHP executable, which will depend on on the version of PHP you’re running. For 7.2.1, the following below would be the proper path
*/1 * * * * /Applications/MAMP/bin/php/php7.2.1/bin/php /Users/clientsupport1/localhost/servercheck/cron/status.cron.php
I want to call a php script every minute using cron
i added the the below code in my crontab file
*/1 * * * * /usr/bin/php /var/www/html/test.php
but it dint give me the desired output.
Am i missing something?
Thanks in advance
You might want to check what happens when this php file runs by following
just use * instead of */1
* * * * * /usr/bin/php /var/www/html/test.php >> /var/www/html/test.txt
test.txt file will contain any error or anything else which cause your test.php to not working. and if it's not loading anything in test.txt, please double check your path to your file.
alternatively try running /usr/bin/php /var/www/html/test.php from your centos console to check whether everything ok with path to your 'php' and 'test.php' file.
I am setting my cronjob as:
*/5 * * * * /usr/local/lib/php /home/..app/webroot/cron_dispatcher.php /devices/checkForAlert
whereas in checkForAlert function of devices controller i’ve just printed ‘hi’ but mail from cronjob only contains this
/bin/sh: /usr/local/lib/php: is a directory
Can you please tell me that is going wrong here…
To have a portable solution you can use env :
*/5 * * * * /usr/bin/env php /home/..app/webroot/cron_dispatcher.php /devices/checkForAlert
/usr/local/lib/php: is a directory
You have provided the path to a directory called php, rather than the php binary.
Try typing whereis php and replacing the above path with the one returned:
> whereis php
php: /usr/bin/php /usr/share/man/man1/php.1.gz
For example, that would be /usr/bin/php in the above output.
I need to send emails hourly and daily. I've tried nearly everything but it appears my crontab just won't work. If I run the scripts via a browser e.g
http://localhost/Maisha/Functions/sendhourlymails.php
my emails get sent beautifully.(I moved default website localhost to public_html.) I don't know whats wrong. I read some post in stack overflow including the executable path of php helps hence I've put the /usr/bin/php before the actual script to be cronned will work but it does not. Removing /usr/bin/php does not work. Adding php before the actual script isn't working.
I have the following entries in my crontab.
# m h dom mon dow command
0 * * * * /usr/bin/php /home/maxwell/public_html/Maisha/Functions/sendhourlymails.php
0 0 * * * /usr/bin/php /home/maxwell/public_html/Maisha/Functions/senddailymails.php
Try to call the script via http with wget like so:
* * * * * wget http://localhost/myscript >/dev/null 2>&1
Yeh, wget is good option, also you can try to use:
0 * * * * /usr/sbin/php /usr/bin/php /home/maxwell/public_html/Maisha/Functions/sendhourlymails.php
but it could work wrong due to relative paths.
Also you should look at http://php.net/manual/en/features.commandline.php
Try to put this into your .php file
<?php
#!/usr/local/bin/php -q
//your code here
?>
Then if you include any file into this file you must use something like:
include"/var/www/../your_absolute_path_from_root_folder/connect.php";
Finnaly make sure this file has the right permissions..Try
chmod 755 /var/www/.../file.php
Then if you edit your crontab file with the following command
vi /etc/crontab
put something like
10 6 * * * root php /var/www/..path../file.php
and restart the service with this command
/etc/init.d/cron restart
you have do your job!!
Note-Tip:the php file isn't neccessery to be into public_html
folder!!