I have this crontab script on my CentOS server:
30 09 * * * /usr/bin/php - f /path/to/my/file.php > /same/path/error.log
This script is needed in order to create - daily - some pdf files in the subfolder pdf/.
I tried many options (php with or without path, with or without -f, etc.) I tried to change permission for the files in the subfolder (becouse these files are overwrited everyday).
But when I execute the script, here is the error.log:
TCPDF ERROR: Unable to create output file: pdf/myfile.pdf
But whe i run this script from shell, using
php file.php
or directly from browser, this is working.
Please, some advice on this issue? Thanks in advance.
Cpanel: wget -O - -q -t 1 http://www.happiweb.net/2014/02/thiet-ke-website-bang-wordpress-gia-re.html
http://domain.com/a.php: change to your URL
Related
When I am trying To access a code that is with a cron using fetch URL :
nohup youtube-dl -o '/var/www/vhosts/domain.com/httpdocs/uploadvideos/1506561898.flv' http://www.dailymotion.com/embed/video/x61ykcu 2> /dev/null & echo $!
i.e : domain.com is my domain name that i have not mentioned here ...
it is not downloading the specified file.
But when i used the same code in Putty(Shell) it download the file in the mentioned folder with the specified name ...
I don't know why it is not working with cron..
Anyone please help me Thanks in advance.
Add the code to the top of the crontab -e file.
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
I'm trying to run a php script every day at 01:00 UTC. I have the line
00 01 * * * /usr/bin/php -f /var/www/html/test.php
in my crontab, but for some reason it's not running my script. I know the script itself works because I've tested it. It just won't run in the crontab. I've also tried using
00 01 * * * php /var/www/html/test.php
but that didn't work either. I've added #!/usr/bin/php to the very beginning of the php script I am trying to run. I've also tried a -q instead of -f. Nothing has worked, and I'm not sure what I can do to fix this. Is there some other method I should try if this still doesn't work?
Make sure your paths are correct. Try this syntax:
cd /var/www/html; php -q -c ./ test.php
The -q flag suppresses any header() from being written to standard out. This forces your script to be executed with the php-cgi binary instead of the command-line version.
The -c flag prevents the OS from changing directories since you do that with cd.
What I ended up doing was writing a ksh script that exported more paths and then ran the php script. This worked.
export ORACLE_HOME=/opt/oracle/product/11.2.0/client
export LD_LIBRARY_PATH=/opt/oracle/product/11.2.0/client/lib/
export PATH=$PATH:/opt/oracle/product/11.2.0/client/bin
php /var/www/html/test.php
having a local
web server running, you may call
http://localhost/test.php
from your crontab
This is my very first time running a cron job on Elastic Beanstalk (EB). After deploying my code, it seems the cron job is created and running but the PHP script is not executing correctly. Here's my set-up.
In my .ebextensions folder I have a file called 01run.config.
container_commands:
01_remove_old_cron_jobs:
command: "crontab -r || exit 0"
02_cronjobs:
command: "cat .ebextensions/cron_jobs.txt > /etc/cron.d/cron_job && chmod 644 /etc/cron.d/cron_job"
leader_only: true
In my .ebextensions folder I also have a cron_jobs.txt file. Please note that I have an line break at the end of this file as instructed by another stackoverflow post. In my example below I am running the command as ec2-user but I also tried root.
* * * * * ec2-user /usr/bin/php -q /var/app/current/tests/cron.php
After deploying my code, I can see that the file /etc/cron.d/cron_job has been created. I can also see the cron job running every minute when I run sudo tail /var/log/cron.
[ec2-user#ip-xxx-xxx-xxx-xxx ~]$ sudo tail /var/log/cron
Apr 13 12:54:53 ip-xxx-xxx-xxx-xxx crontab[26093]: (root) DELETE (root)
Apr 13 12:55:01 ip-xxx-xxx-xxx-xxx crond[1230]: (*system*) RELOAD (/etc/cron.d/cron_job)
Apr 13 12:55:01 ip-xxx-xxx-xxx-xxx CROND[26128]: (ec2-user) CMD (/usr/bin/php -q /var/app/current/tests/cron.php)
Apr 13 12:56:01 ip-xxx-xxx-xxx-xxx CROND[26139]: (ec2-user) CMD (/usr/bin/php -q /var/app/current/tests/cron.php)
Within /var/app/current/tests/cron.php I have some code that adds a row to a MySQL database (hosted on RDS). But nothing is being added to the database.
I then tried running the cron command directly through my terminal window:
$ /usr/bin/php -q /var/app/current/tests/cron.php
And it runs without error and adds the record to the database. I am logged in as ec2-user in terminal.
Have I missed something? Or is my cron job code set-up incorrectly?
I had a similar problem with a php script that was trying to access an AWS RDS database. Is your php script getting the database details with $_SERVER['RDS_xxxx']? If so, those RDS_xxxx variables don't exist in the environment when the php script is run by cron.
In order to fix this, I added the variables to the beginning of the cron file:
RDS_HOSTNAME=<my_database_hostname>
RDS_PORT=<my_database_port>
RDS_USERNAME=<my_database_username>
RDS_PASSWORD=<my_database_password>
RDS_DB_NAME=<my_database_name>
* * * * * php /path/to/my/script.php
Login via SSH and check if generated cron job file/etc/cron.d/cron_job have unix line ending i.e. ASCII text not win i.e. ASCII text, with CRLF line terminators.
To check the line ending refer the answer here.
Note: If you have windows line ending then you will have to convert the line ending of file .ebextensions/cron_jobs.txt, for that you can use dos2unix or similar program.
I had a similar problem with my RDS_ variables on AWS, I followed this discussion and it works.
This was my cronjob before:
RDS_HOSTNAME=<my_database_hostname>
RDS_PORT=<my_database_port>
RDS_USERNAME=<my_database_username>
RDS_PASSWORD=<my_database_password>
RDS_DB_NAME=<my_database_name>
* * * * * cd /var/app/current && bin/cake notifications send_push >> /var/tmp/notifications.log 2>&1
And changed to this:
* * * * * . /opt/elasticbeanstalk/support/envvars cd /var/app/current && bin/cake notifications send_push >> /var/tmp/notifications.log 2>&1
And now I can access them like: $_SERVER['RDS_HOSTNAME']
I am trying to run a crontab on Ubuntu, I think I get the general idea of how to create a crontab
I did the following...
1) run command crontab -e
2) add entry 04 22 * * * /var/www/update_ranks >> /root/update_ranks.root.txt
3) check a text file was created under root/ named update_ranks.root.txt at the specified
time.
The file update_ranks.root.txt is empty and the php file is not executed, what am I doing wrong?
If update_ranks is a bash file try adding sh before the script sh /var/www/update_ranks
By the way, check if you are doing that as root user or user with writing rights to /root. Try sudo crontab -e.
EDIT:
If it's a PHP file, you need to execute it in php /usr/bin/php /var/www/update_ranks and if the file has extension, use this: /usr/bin/php /var/www/update_ranks.php
What should be given as the url to the script while adding it to cron scheduler. The script is at domain.com/scripts/script.php
PS:I am using cPanel
If you add the line
#!/usr/bin/php
to the beginning of your file (use 'which php' to find out your actual directory) and change the file mod to "executable", you should be able to run it just by calling like your second choice,
/public_html/scripts/script.php
I hope that works for you.
Here's a copy / paste out of one of the cron jobs that I run:
00 7 * * 1,2,3,4,5
/usr/local/bin/php
/home/processing/process.php
You must use the absolute path to the PHP binary as well as the absolute path to the script itself.
none of these.
but full absolute path from the root of the filesystem.
you can see that path with this code
echo __FILE__;
I had the habit of changing directory cd /var/www/vhosts/somesite.com/httdocs before running script with /usr/bin/php -f ./scriptname.php 2>&1 all in the same line on crontab.
I redirect the error output to get notified by email in case an execution error occured.
From crontab :
MAILTO=emailnotifications#mail.com
* * * * * cd /var/www/vhosts/domain.com/httpdocs/; /usr/bin/php -f testmail.php 2>&1