cron task not working in centos - php

I have an unknown problem like cron task is not running at all.. I have checked the cron status
# service crond status
crond (pid 30949) is running...
But task is not running, check my crontab list below
# crontab -l
* * * * * echo -e "\aBEEEP\n"
*/1 * * * * echo -e "\aBEEEP\n"
I added this, to check task is running or not. What is the issue, may be permission ??
No update in /var/log/cron
Thanks in advnace..

Where do you expect the echo output? Your terminal is not connected to this process.
to test if cron is working try, e.g.:
* * * * * touch /root/crontest
File will be created after 1 minute then.

Related

how to create crontab for auto run command "service php-fpm restart" in centos 6?

I want to run command "service php-fpm restart" each 1 minute and I tried to using contab.
I tried this code in contab file:
0/1 * * * * service php-fpm restart
In the file crontab from /var/spool/con/root, I put these code:
0 2 * * * chown -R nginx:nginx /home/
0 3 * * * echo 1 > /proc/sys/vm/drop_caches
0 4 * * * reboot
0/1 * * * * service php-fpm restart
All the command almost are running , but the command "service php-fpm restart" not.
Besides the big question of why you need to restart every minute (feels like fixing a flat by making sure you have a airpump handy instead of stopping the leak) I wonder how you got a minute of "0/1"? To run something every minute you give it five stars
* * * * * /sbin/service php-fpm restart

Magento 2.1.8 Re-indexing Error

I'm new to Magento and I am having a trouble with Re-indexing.
I have checked all of the questions with re-indexing problem but my problem is different.
My Cron job is showing the following error:
Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.
I have removed the memory_limit in php.ini, but it's still the same.
My Cron Job:
***** php /home/username/public_html/update/cron.php >> /home/username/public_html/var/log/update.cron.log
Can anyone help?
The Following command:
* * * * * <path_to_php> <magento2_dir>/update/cron.php >> <magento2_dir>/var/log/update.cron.log
is giving the ouput
X-Powered-By: PHP/5.6.31
Content-type: text/html; charset=UTF-8
But. My index aren't being reindexed. I'm using Cpanel.
you need to setup proper CRON for your Magento2 Web Store:
to setup CRON you need to do following :
login via SSH to your server
edit cronjobs with this command
crontab -e
after this a text editor displays. (You might need to choose a text editor first.)
here you need to add following lines ( make sure to change paths for your enviornment )
* * * * * <path_to_php> <magento2_dir>/bin/magento cron:run | grep -v "Ran jobs by schedule" >> <magento2_dir>/var/log/magento.cron.log
* * * * * <path_to_php> <magento2_dir>/update/cron.php >> <magento2_dir>/var/log/update.cron.log
* * * * * <path_to_php> <magento2_dir>/bin/magento setup:cron:run >> <magento2_dir>/var/log/setup.cron.log
here:
<path_to_php> is usually /usr/bin/php you can find this by command which php
if you have installed php-cli than you need to assign path for php-cli here
<magento2_dir> is the Root directory for Magento2 Installation.
Following is must have CRON for Magento2
bin/magento cron:run
Ex:
* * * * * /usr/bin/php /home/username/public_html/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /home/username/public_html/var/log/magento.cron.log
* * * * * /usr/bin/php /home/username/public_html/update/cron.php >> /home/username/public_html/var/log/update.cron.log
* * * * * /usr/bin/php /home/username/public_html/bin/magento setup:cron:run >> /home/username/public_html/var/log/setup.cron.log
NOTE : IF you have cPanel or other Panels than you need to find cron / scheduler and setup the same there accordingly
You have to contact your server guy regarding that. They will increase the server memory limit. Or you can do on thing. First do the indexing using SSH and then try to set cron job. I hope it will help you.

How to run a PHP script using a Cron job

I'm having a PHP script which I want to run every 2 minutes using a Cron job in Ubuntu. I'm getting the following error:
bash: */2: No such file or directory
I've completed all steps below to set up a Cron job.
Please help me to resolve the error, I don't understand what I'm doing wrong.
1) Write this command in my terminal: where is php
Output:
php: /usr/bin/php /usr/bin/X11/php /usr/share/php /opt/lampp/bin/php /usr/share/man/man1/php.1.gz
2) Run a PHP script every 2 minutes:
*/2 * * * * /usr/bin/php /opt/lampp/htdocs/kyrill/filetest.php
Output:
bash: */2: No such file or directory
Seems like you are executing the crontab directive.
Execute
crontab -e
to edit your cron jobs. Then add this line at end of the file
*/2 * * * * /usr/bin/php /opt/lampp/htdocs/kyrill/filetest.php
try
0/2 * * * * curl http://[your_id:port]/kyrill/filetest.php

php crontab -l showing different result from command line

I created a file name 'testCrontab.php' in /var/www/html folder on amazon ec2, ubuntu-based,
$output = shell_exec('crontab -l');
var_dump($output);
The problem is when I invoked this file in browser it shows
string(207) "0 0,6,12,18 * * * /usr/bin/php /var/www/html/testExec.php 0 3 * * * /usr/bin/php /var/www/html/testCrawlback.php 0 4 * * * /usr/bin/php /var/www/html/testInsertCard.php * * * * * NEW_CRON * * * * * NEW_CRON "
Which I guessed those NEW_CRON are from the other time I tested inserting a new cron from php,
but when I invoked this file from command line by issuing /usr/bin/php /var/www/html/testCrontab.php it shows
string(169) "0 0,6,12,18 * * * /usr/bin/php /var/www/html/testExec.php
0 3 * * * /usr/bin/php /var/www/html/testCrawlback.php
0 4 * * * /usr/bin/php /var/www/html/testInsertCard.php"
Also, command crontab -l result in the latter output.
Please help enlighten me what happen here.
Result will be different because when you are executing script via browser the user will be www-data or nobody. It will show the crons of that user. If you execute the script from command line it will show the crons of that particular user.
Edit
Set cron for webuser
sudo crontab -u webuser -e
List crons of webuser
sudo crontab -u webuser -l
webuser will be nobody or www-data or apache
You can find it by executing the following code from web browser.
<?php $output = exec('whoami');
echo $output;
?>

PHP Exec Crontab Not Doing Anything

I am trying to set up a cron job using a PHP script. This works fine on my computer running XAMPP but when I try it on my web host (Just Host) it's not adding it to the list of cron jobs. Here is the PHP code:
exec('crontab cronfile.txt');
cronfile.txt Contents:
* * * * * /usr/bin/php -q /home/-username-/public_html/cron/cron.php 1
This does however work when I add it through cPanel and I can view any cron jobs by using shell_exec('crontab -l'). Any ideas how to resolve this?
Most likely Apache is running as a different user than username, so it won't update usernames crontab file. Run the script
<?php phpinfo()
and verify which user Apache is running as.
On my system, I see the following
User/Group apache(48)/48
You should use this exec('crontab /tmp/cronfile.txt')
and it will work.
You can add every script to this file.
example:
touch /tmp/cronfile.txt
vi /tmp/cronfile.txt
* * * * * path-to-script
* * * * * path-to-script2
.
.
finally
crontab /tmp/cronfile.txt
crontab -l you will see your cron list

Categories