Cronjob won't execute on 1and1 server - cron

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...

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.

Entry in cron.d not executed

I have a cron task configured in cron.d directory that would get executed for every 5 minutes. The entry is
*/5 * * * * root /usr/sbin/logrotate /etc/logrotate.d/test_consolelog
This would invoke the logrotate. However the logrotate didn't happen. I checked the /var/log/cron file to see if cron executes the command and could see that the command is getting executed for every 5 minutes.
I tried executing the command mannually on the terminal and could see that the command is executed and log rotation happens.
What could be reason that logrotate is not happening when getting executed from cron.d.
Regars,
Bala
I found the root cause. The SELinux needs to be disabled for this to work. Earlier while testing the sestatus value is disabled in the the /etc/selinux/config file however the current status was enforcing. Once i restarted the vm itself the sestatus updated to disabled and logrotate functioned as desired. prior to that i have fixed the bad minute error too.
I had furnished enough details for this post and done enough research before posting here. However i am not sure why some one marked this post as there is no research effort or unclear or unuseful...

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.

Cronjob on Amazon EC2 Deleted?

I had a cronjob set up to run a php script daily, which went well for about a month. Today, I realized it didn't run the script so I opened up the crontab. The crontab is completely empty - what happened?
I don't know too much about cronjobs, but as far as I understand, they do not delete themselves if the server is reset. How can I make sure cronjobs are always running and that it doesnt get deleted?
It is probably under a different user. Check root user sudo crontab -e. Each user has it's own crontab and there's one for the whole system. Note: Through the crontab configuration you can disable per-user crontabs.

getting No such file or directory error for cron job

I wanted to run the following file from a cron job and got No such file or directory error, please help.
/var/www/vhosts/domain.com/httpdocs/filename.php
Just use a service like WebBasedCron (google it) to schedule your cron job remotely. If you can access the filename.php file from a browser like FireFox, then you can execute the cron job.

Resources