CyberPanel Community

ClosedSetup a cronjob for a php file

AA
Amin Aenurahman #1

Hi there, I want to setup cronjob using curl

as example

curl --silent https://website.com/export-txt.php > /home/cyberpanel/public_html/output.txt

I have tested that command directly via terminal and its working
but somehow I set it on cronjob and it did not work

is it need to use using different command to use in cronjob?

Oh anyway, I install cyberpanel on VPS Ubuntu 20.04
Thank you in advance

9 replies
jo
josephgodwinke #2

Welcome @am1ncmd Happy you are here

You are trying to setup a cronjob for a php file. Psst that should be the title.

Solution:

php /home/mydomain.com/public_html/test.php >> /home/mydomain.com/public_html/output.txt

To use a different PHP version:

/usr/local/lsws/lsphp81/bin/php /home/mydomain.com/public_html/test.php >> /home/mydomain.com/public_html/output.txt

For quiet mode:

php -q /home/mydomain.com/public_html/test.php >> /home/mydomain.com/public_html/output.txt
AA
Amin Aenurahman #3

The reason why I use CURL instead of PHP is the source https://website.com/export-txt.php is using different website

I already tried using the PHP command but the output.txt is still not showing on the directory

Also, thank you for suggesting the tittle

jo
josephgodwinke #4

Does the world have access rights to that php file?

AA
Amin Aenurahman #5

I own that website, just using different hosting and also a different panel

cyber panel installed on VPS, and the other one is using the default panel from the hosting itself

AA
Amin Aenurahman #7

Yes, of course, It can be access it from anywhere on any devices

jo
josephgodwinke #8

Try the system wide cron nano /etc/crontab add this line at the end to run every minute so that we confirm if it ran:

* *    * * *   root /usr/bin/wget -O - https://website.com/export-txt.php >> /home/mydomain.com/public_html/output.txt

why wget its just my preference.

AA
Amin Aenurahman #9

Alright, this one is working using curl. Thank you so much

But I still have a question: why is not working with the default cronjob from the cyber panel?

jo
josephgodwinke #10

All cronjobs are here /var/spool/cron/crontabs you can always view your conrjobs by running crontab -l I believe the trick was running as root OR it failed during creation in cyberpanel. Can you check your logs for any errors

Sign in to reply