How can i set a cron job in Zpanel - php

in C panel we can set url in cron job like
wget example.com/homes/action
Or
absolute path
/usr/bin/php -q /home/mohanphp/www/quote_bot/sms_cron.php
but Zpanel dose not support full url
and i want to call an action (in Cakephp eg http://abc.com/homes/corn_job/daily/ )
in c panel there is no problem but Zpenal how to do this ??
thanks

You can better check the link set a cron job in Zpanel.
touch /etc/cron.d/zdaemon
echo "*/5 * * * * root /usr/bin/php -q /etc/zpanel/panel/bin/daemon.php >> /dev/null 2>&1" >> /etc/cron.d/zdaemon
chmod 644 /etc/cron.d/zdaemon

If you are trying to run the URL, just because you want to run an action of a cakephp controller. Then you should try to use a dispatcher, which will let you execute a controller action from the command prompt and then you can setup the cron as normal in zpanel.
More information about the cron dispatcher could be found here:
http://colorblindprogramming.com/cronjobs-in-cakephp-2-in-5-steps

Related

Cron tab doesn't run most of tasks

I setup several cron jobs to make things work. laravel scheduler works perfectly but my other cronjobs not working at all.
*/2 * * * * /usr/bin/php /var/www/cronjobs/index.php
when I run on the console /usr/bin/php /var/www/cronjobs/index.php it works properly. I checked executable php path with which php and gives me /usr/bin/php nothing wrong with path afaik. I tried to run php script as apache user www-data I opened crontab with crontab -u www-data -e and paste command there.. it didn't work too.
I also tried send dummy notify with crontab and it also didn't work either
dummy example
* * * * * /usr/bin/notify-send 'test'
both of them doesn't work. What am I missing here ?
The second command will not send notification as cron have no idea of your desktop environment.
The first command probably use some environment variables. So instead of run in command line you can try to create a script:
#!/bin/bash
source /path/to/user/home/.bashrc #you can try also .bash_profile
/usr/bin/php /var/www/cronjobs/index.php
and your cron to be like:
*/2 * * * * /path/to/script.sh

Run a Cron Job In Cpanel with CURL

I have a code in laravel, I want to setup a cron job in cpanel But I don't know how to. I saw several examples that has file name to cron, but I am using Laravel so how can I point this to URL route?
/usr/bin/curl https://example.com/cron_route
I am not sure is this correct method or I can do that in different way, well I canot use laravel artisan scheduler, I have all custom code and custom Controller.
can anyone help me out with this?
Try this command
1 1 * * 0 /usr/bin/curl -m 120 -s https://example.com/cron_route &>/dev/null
To add cronjob using command line, use this command
0 2 * * * wget -q -O /dev/null http://example.com/cron_script
See for reference : https://crontab.guru/

What command would I use to run a cron job on a file not in public_html

I have a php file which I want to be executed every 15 minutes. I have the cron job set up already. I just want to know what command I would use?
My file is located in ~/app/example/myfile.php. So you can't access it through a URL. Otherwise I would have just used wget -q -O /dev/null "URL"
In your crontab it'd be
0,15,30,45 * * * * php /path/to/file.php

PHP not working with CRON

I'm using crontab to call a php script.
In this script there is
error_log('test');
When the script is executed from http or direct command line like
php -f script.php
Everything is fine, my error is log.
But when called from cron it's not working.
Here is my cron
* * * * * -u www-data /full_path_to/php -f /full_path_to/script.php
Here is what I tried :
error_log with arguments :
error_log('test', 3, '/full_path_to/error.log');
changing error reporting :
error_reporting(E_ALL);
ini_set('display_errors','On');
ini_set('error_log', '/full_path_to/error.log');
cron call ending with > /full_path_to/error.log 2>&1 (don't know if useful)
For http the error_log path is set from htaccess.
I'm lost with php cli...
I can see the cron execution working every minute (syslog), so it should be a PHP config problem ?
Thanks a lot if you can help.
Edit : Cron is executed with "-u www-data"
Here is the call I see in syslog :
CRON[13921]: (www-data) CMD (-u www-data /usr/bin/php -f /fullpath/script.php > /fullpath/error.log 2>&1)
I was facing the same problem but was able to fix it after reading the manual entry for php.
Initially I had something set like:
/usr/bin/php -f /path/to/php/script.php -c 1426 >> /tmp/script.php.log 2>&1
I was able to fix it by changing the line to:
/usr/bin/php -f /path/to/php/script.php -- -c 1426 >> /tmp/script.php.log 2>&1
As per the manual entry the syntax is:
php [options] [ -f ] file [[--] args...]
Also,
args... Arguments passed to script. Use '--' args when first argument starts with '-' or script is read from stdin
Going by that, my cron command becomes:
/usr/bin/php -f /path/to/php/script.php -- -c 1426 >> /tmp/script.php.log 2>&1
and it works!
You have to be aware that there are user specific crontabs and a system wide crontab.
When you are logged in as user foo and type crontab -e in console this will allow you to edit your own user specific crontab. All defined cron tasks will be executed as user foo. This is even true for user root. AFAIK this way you simply can not change the user under which a cron task will be run.
Quite different is the file /etc/crontab. This is the system wide crontab. Within that file you can change the user of a cron task like this:
* * * * * www-data /full_path_to/php -f /full_path_to/script.php
I had in fact two problems :
1) My cron was executed with php.ini for php-cli. I used the -c flag to load the good one.
2) I was relying on $_SERVER to declare important constants using variables that do not exist in cli-mode. Now if these variables are not set I parse commande line vars with getopt()

Problem running a small script as cron job

I am problem scheduling and running a script through cron job. I am on linux (ubuntu), it is a VPS.
What I am doing is I have put this line in crontab file that is here: /etc/crontab
I wrote:
*/15 * * * * www-data php /var/www/abs/phpscript.php
I have given 777 to the file and after writing above in crontab , I run command:
crontab crontab
Then after almost some time I got the mail in my /var/mail/username file that says: /bin/sh: root: not found
So I am unable to understand what is the problem.
I also run phpinfo and it shows the third variable as APACHE that probably means that PHP is running as apache module.
Please tell what can be the possible solution.
thanks in advance to every one who will try to solve my problem.
You can try also to run it using "wget -q -O"
or
*/15 * * * * lynx -dump "url" > /dev/null
Wget examples:
*/15 * * * * wget -O /dev/null 'http://www.mydomain.com/document.php?&user=myuser&password=mypass' >/dev/null
If you need to post data you can use
--post-data "login=user&password=pass"
*/15 * * * * wget -O /dev/null 'http://www.mydomain.com/document.php?&user=myuser&password=mypass' --post-data 'foo=bar' >/dev/null
If you edited /etc/crontab, you should re-read the warning at the top of the file:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
Running crontab(1) on the /etc/crontab file probably contaminated the root user's crontab(5) file (the one stored in /var/spool/cron/crontabs/). I suggest running crontab -e as root to edit the crontab file, and remove all the entries that are identical to the entries from /etc/crontab. (Maybe you just contaminated your own personal crontab(5) -- if crontab -e as root didn't show anything, run crontab -e under your own personal account and see if the system-wide entries were duplicated into your own crontab(5).)
I don't know what file you ran chmod 777 on, but that was probably unnecessary. You really should set your permissions to be as strict as possible to confine the results of malicious attacks or unintentional mistakes.
You are running a crontab as a user, which means you can't specify the user in the cron.
The template you borrowed your example from was for a system (root) cron.
Remove the username and try again.

Categories