Cronjob PHP script don't works - cron

I've tried several suggestions here on the site, but I couldn't, that's why I'm opening this question.
I created a cronjob (CENTOS7), with the following:
***** /usr/bin/php /var/www/domain.com/html/v1/backend/files/teste.php
But it doesn't run, but if I run the command below it works:
php /var/www/domain.com/html/v1/backend/files/teste.php

Related

Node script runs manually but fails in crontab

Currently am running a few js files manually on a semi weekly bases for my company. I stumbled on the possibility of automating these runs in to cron jobs. Im fairly novice to shell scripts and was able to achieve this on an outdated personal mac mini I have.
When trying to replicate the same setup on a company owned device, I hit a wall. I think it has something to do with user permissions or current user cron differing from sudo cron. (The user I have is the only user on the device.)
I can manually run this script on the current user macserver#Mac-mini ~ % , utilizing the node NVM_BIN I downloaded through homebrew and it runs fine.
Terminal entry like this:
cd Desktop/main-tool && /Users/macserver/.nvm/versions/node/v18.12.1/bin/node main.js
I then try accessing cron using the nano editor EDITOR=nano crontab -e adding the command above except with the scheduling expression and nothing happens.
Cron entry like this:
* * * * * cd Desktop/main-tool && /Users/macserver/.nvm/versions/node/v18.12.1/bin/node main.js
Is there a way to view if cron jobs are running instead of just viewing an active list? Not sure where to start trouble shooting as the information I have come across references anywhere from changing root variables for users to complete environment overhaul which I would like to avoid.
My PATH and SHELL:
$SHELL=/bin/zsh
$PATH=/Users/macserver/.nvm/versions/node/v18.12.1/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Let me know if any other info might help.

Permission Denied with crontab

I try to execute a script (on my personal pc, Linux Mint) who execute two other scripts who launch two servers (one script for a Symfony server and one for a webpack server) using cron. So I put this line inside my crontab
#reboot /usr/local/bin/launchFm.sh 2>&1 ~/Documents/script/errorcron
inside ~/Documents/script/errorcron file I got this line
Unable to init server: Impossible de se connecter : Connexion refusée
Yeah I'm french but it's basically connection denied.
I can execute this script by manullay and it works fine. Also, I tried to execute a dummy script inside the crontab like #reboot touch test, and this work perfectly fine. I have no cron.deny or cron.allow file.
I got this permission for the /usr/local/bin/launchFm.sh -rwxr-xr-x and I'm the owner. So everybody got the x(execute) permission. The error says Unable to init server but I got nothing inside the error log of the script who launch server so I think the problem is the crontab permission but basic script work fine so I'm very confuse
I solved it by calling the two scripts instead of calling the script who execute the two "subscript". It's not elegant but it work.

Cronjob won't execute on 1and1 server

I have 1and1 web hosting. I am supposed to be able to set up cron jobs using crontab to execute on the server. I have a job set up as follows (including showing the full path to my PHP installation):
(uiserver):u*******:~ > which php5.4
/usr/local/bin/php5.4
(uiserver):u*******:~ > crontab -l
20 * * * * /usr/local/bin/php5.4 /kunden/homepages/40/d*******/htdocs/job.php
If I execute the command manually in the terminal, it runs fine. But the cron job never runs.
Am I missing something obvious?
I've tried checking the cron logs, but I just get permission denied, unfortunately, so that was no help for troubleshooting. The joys of being on somebody else's server, I guess...

Why is my cron job not running?

I am trying to run a cron job at 5:20pm as below but it's not working.
20 17 * * 1 /usr/bin/php /home/myacc/public_html/job/generate.php
I basically did crontab -e and entered the above line there and saved the file.
If I try running the command directly from the command line as below, it works fine:
php /home/myacc/public_html/job/generate.php
What am I doing wrong?
Also, how do I send a message from the cron to either a log file or email so that I know what's going on?
You can record all the logs of your cronjobs by installing postfix and configuring it as local domain during installation. Such that you can see the logs of your cron jobs by vi /var/mail/<user-name>. Try looking the logs and figure out the problem. If you don't find any solution post the log so that it will help others to diagnose the problem. I'm adding this as an answer instead of comment because i think I'm answering your second query.

cron job does not work in cpanel

I have put this command line in Cpanel cronjob
/usr/local/bin/php -q /public_html/myfolder/directory/admin/cron.php
and got this error
Could not open input file: /public_html/myfolder/directory/admin/cron.php
I have checked, the file is there in the folder. This is basically a script that sends a login
reminder to every member of the MySQL database. The script runs successfully if I launch it from the URL in browser.
Use full path:
php -q /home/username/public_html/myfolder/directory/admin/cron.php
Or simply use get the URL :
GET http://example.com/myfolder/directory/admin/cron.php

Resources