I tried setting up a cronjob from cpanel to run a php script every minute but nothing happens and the logs doesn't show any error. When i run the php script manually everything works fine.
This is the cron command
/usr/local/bin/php /home/alinut/public_html/b2b/parteneri-xml.php > /home/alinut/logs/cron-local.log 2>&1
This are the includes in the script
include(dirname( __FILE__ ) . '/config/config.inc.php');
include(dirname( __FILE__ ) . '/init.php');
And this is where it should save an xml
$domtree->save(dirname( __FILE__ ) . '/xml/test.xml');
I found a solution by using wget
wget -q https://example.com/parteneri-xml.php
Related
I have a script .sh that works when executed manually but not working through cron :
#!/bin/sh
sudo find . -name "*.log" -delete
There are other .sh which runs perfectly with cron.
I don't know why this one doesn't work.
I compared the env output from the terminal and from cron and both are similar beside the user which has higher privilege in cron using :
echo env > output.txt
The only difference between this script and others which work is the location of the file.
If anyone had a similar problem or know how to get more precise logs.
Thank you in advance
As mentioned by #Shawn and #user1834428 in the comment the "." in my script was not pointing where I wanted.
i have problems with Cron jobs, it's always said "No such file or directory"
I tried everything but it's still not working on that cPanel.
-q /home/user/tracker.domain.com/cron/3.php
It's using subdomain who is not in public_html.
You have to specify the full php binary path inside the cronjob. Assuming your php binary full path is /usr/bin/php then your cronjob will look like this:
/usr/bin/php -q /home/user/tracker.domain.com/cron/3.php
You should use php before -q in your cron jobs like this
php -q /home/user/tracker.domain.com/cron/3.php
I want to try how to render html from R markdown file but from a bash script running as Cron jobs. I don't know why everything works fine, except running as Cron jobs. What I do:
My script is a demo script from Rstudio
---
title: "test"
author: "sms"
date: "24 maja 2015"
output: html_document
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
etc.
This script works without any problem in Rstudio.
Next I try to run an Rmd script from terminal:
Rscript -e "require( 'rmarkdown' ); render('/home/sms/Dokumenty/R/test.Rmd', 'html_document')"
There wasn't any problem. It works.
So I create bash script
#!/bin/bash
Rscript -e "require('rmarkdown'); render('/home/sms/Dokumenty/R/test.Rmd', 'html_document')"
and changed chmod 755 test.sh
Also works like a charme.
But when put in Cron file (admin and user):
28 18 * * * sh /home/sms/Dokumenty/R/test.sh
It doesn't works
Any idea what am I doing wrong?
I had the same problem.
The issue is because I was running the Rscript as root, but Rscript should be run as souza, current user.
To fix that, I edited the crontab for user souza "sudo crontab -u souza -e" and the Rscript is run as souza and not as root.
Now it is working
Simplify, simplify, simplify.
First, I'd make it an Rscript, maybe called renderTest.R
#!/usr/bin/Rscript
library(rmarkdown)
setwd("/home/sms/Dokuments/R")
render("test.Rmd") # I usually use default arguments
Second, make the script executable (chmod 0755 renderTest.R).
Third, test the script. If you can run it as you, a cron job running as you should too.
Fourth, add the cronjob running as you to have the same rights.
Edit I just fixed a typo I copied from you: Documents/ not Documenty/.
I have the same problems.
But it would work if you try to use knitr::knit2html instead of rmarkdown::render
on idea why
I have a script in which I connect as sysdba and run a query.The script works perfectly fine when I run it standalone by sh command.But when I run the script from a cronjob the script runs but the sql part is omitted .
My script is like
echo "before connection"
sqlplus / as sysdba << EOF
Select * from dual
EOF
It works perfectly fine when I run by:
sh script_name.sh
But When I run by a cronjob the connection part is omitted only line which I get in my logs in "before connection"
What could be the solution of this problem?
Perhaps you get the error sqlplus not found. When run from crontab.
You have to export your PATH variable in the script explicitly. Else, load the .profile itself, if needed. Because, your crontab just executes the script, without defining the variables that you had in your .profile.
Add this to your script, to always load your .profile
. $HOME/.profile
OR
. ~/.profile
If you are running on UNIX (UNIX-like) systems, shebang is mandatory. Have you tried shebang on the first line ? (bash is the shell of choice in my systems)
#!/bin/bash
More explanation here.
I have a php script in my website folder that needs to be executed weekly.
I am on debian 6 (root).
How can I run this php script (in cli) weekly wihtout using crontab ?
I mean which kind of file should I copy in /etc/cron.weekly to run my php file?
Just use an executable PHP script with a "shebang" line:
#!/usr/bin/php
<?php
// Your PHP code goes here
echo "Hello World!";
?>
Make it executable:
$ chmod +x myscript.php
Test it:
$ ./myscript.php
Hello World!
The "shebang" (#!) tells the shell that this script is to be executed with PHP, found in /usr/bin/php.
Alternatively, you could write a small shell script that invokes the PHP interpreter with your PHP script:
#!/bin/bash
/usr/bin/php -f /path/to/script.php