crontab printing script instead of executing it - php

here my problem width crontab:
I need to run a php script everyday at noon and so on my crontab i set:
# 0 0 * * * /usr/bin/php -c /var/www/fanta-trade/operazioni_pianificate_medaglie.php > /var/www/cron_log
0 12 * * * root /usr/bin/php /var/www/offertegaseluce/operazioni_pianificate.php > /var/www/offertegaseluce/cron_log
*/15 * * * * /usr/bin/php -q /var/www/fanta-trade/operazioni_pianificate_ordini.php > /var/www/cron_log
#20 */6 * * * /root/certs/certbot-auto renew --quiet --no-self-upgrade
the line that i need is actually the second... i tried many debugging:
I checked the timezone and it is properly set to europe-rome
I checked width whereis the position of php and /usr/bin/php is correct
I tryed to run the script as root or just widthout user specification
0 12 * * * /usr/bin/php /var/www/offertegaseluce/operazioni_pianificate.php > /var/www/offertegaseluce/cron_log
I checked if crontab as a sevice is running and restarted it
I checked if the script itself is reacheable and if it works and if i call the script via browser it works
but actually crontab is not executing the script it just copy paste the cript itself to the log file
any suggestion?
thanks

Related

How to run CRON jobs on cPanel?

I am trying to set up CRON jobs on cPanel v. 76.0.18 and I get "no input file specified" (NIFS), and looked into other posts (e.g., NIFS1, NIFS 2, NIFS 3, NIFS 4), not sure how to solve it.
My samples of CRON jobs:
*/10 * * * * /usr/bin/php -q /home/dir/dir/cron_dir/file-1.php
0 * * * * /usr/bin/php -q /home/dir/dir/cron_dir/file-2.php
* * * * * /usr/bin/php -q /home/dir/dir/cron_dir/file-3.php
0 * * * * rm -rf /home/dir/dir/data_dir_1
0 0,6 * * * rm -rf /home/dir/dir/data_dir_2
0 0,4 * * * rm -rf /home/dir/dir/data_dir_3
How do I solve "no input file specified" error?
Thanks a million guys!
If the command executes correctly in CLI directly, you might try putting it in a .bash file and referencing that in cron. I've seen weird issues with commands in cron, and sometimes wrapping it in a script can help.
If it /doesn't/ execute correctly in CLI, then you might start there :p

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;
?>

Using Sleep command in Crontab CentOS

I am trying to execute a php script in conjunction with the Sleep command from Crontab. Here is the relevant code:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root HOME=/
# run-parts
* * * * * sleep 5 && root /usr/bin/php /path/to/the/php/file.php
But it won't execute at all. Any hints?
Remove root from sleep 5 && root /usr..
If you want to run it as root, the correct format is:
* * * * * root sleep 5 && /usr/bin/php /path/to/the/php/file.php

Run PHP script at regular intervals using CRON

I am kinda newbie to this, I have a php script which I want to execute after every 1 hour, for this I updated the crontab file inside the /etc directory but I am not able to see whether its actually being called.
Here's the entry in my crontab file
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
*/5 * * * * /usr/bin/curl -o temp.txt http://myurl.com/postparser.php
I am not even able to see any temp.txt file getting generated
Can someone point me in the right direction
try running
*/5 * * * * /usr/bin/php /path/to/php/file/postparser.php
Change the /usr/bin/php part to your php executable path.
Not sure about this but, changing just the file would have no effect.
Try editing the tasks using the command crontab -e ("e" for editing).
If you want to edit the crontab for a certain user, use the -u parameter
for more, check the man:
http://linux.die.net/man/1/crontab
Good luck

Categories