How to run a custom cron job on LightSail server with Bitnami LAMP stack? - cron

I've tried a range of combinations for adding a cron job. I can't tell if there is a problem with my cron command, or if it's something about the users on the server. Currently I've added this cron to run under sudo. I'm confident the path to php and path to my cron are correct, and when I visit that cron.php file it stores the time() in a log so I know that part works... also permissions are 755 on the cron.php file.
*/1 * * * * /opt/bitnami/php/bin/php /opt/bitnami/apache2/htdocs/cron.php cron:run
I've tried adding this cron using sudo crontab -e, sudo crontab -u root -e, crontab -e. I've also tried combinations where the user is state in the cron command like:
*/1 * * * * sudo /opt/bitnami/php/bin/php /opt/bitnami/apache2/htdocs/cron.php
*/1 * * * * root /opt/bitnami/php/bin/php /opt/bitnami/apache2/htdocs/cron.php
*/1 * * * * bitnami /opt/bitnami/php/bin/php /opt/bitnami/apache2/htdocs/cron.php
So far no combination works, and there are no errors in the server log.
I've tried restarting cron with sudo /etc/init.d/cron stop, sudo /etc/init.d/cron start. The start/stop works so I'm sure cron is running... but I'm not sure if cron runs as "root", "sudo" or "bitnami"?

Related

CRON job outputting blank lines

I tried to create a CRON job that runs every minute. As a root user, I ran crontab -e, and in the cronjob, I put in my command * * * * * /usr/bin/php {redacted}/index.php > {redacted}/output.txt
the {redacted} file path has permissions added: chmod ogu+rwx -R so everyone should be able to access it. I even created a new user with no sudo or root privileges, and running /usr/bin/php {redacted}/index.php > {redacted}/output.txt obviously writes the output of {redacted}/index.php to {redacted}/output.txt. However, my cron job ends up overwriting and turning the .txt file to just blank, nothing. I have no idea what is going on since I already made sure there were no permission errors, and cron jobs don't seem to have a visible log or output?
I would love to have any ideas about this. I even tried to add the cron job * * * * * root /usr/bin/php {redacted}/index.php > {redacted}/output.txt, all to the same output.
One more thing... I have tried to set the {redacted} location to /var/www/html, /var/www/{a user with sudo perms}, and {/usr/local/bin} all with the same result.
Update:
I tried something as simple as * * * * * php -v > {redacted}/output.txt and * * * * * /usr/bin/php -v > {redacted}/output.txt still with the same result, so it seems like the error is not with requiring root permissions to run my php program

Cronjobs do not run

I'm trying to run a cronjob to start and stop a server under a non-sudo user. I've tried asking others and doing what I saw from looking on google before asking here, but I'm still stuck.
Here's what's in my crontab for the server user:
* * * * * /home/server/startup/stop.sh
* * * * * /home/server/startup/start.sh
Here is what is in my stop.sh script:
#! /bin/sh
screen -r server -X quit
Everything runs normally if I run it using sh, and I only encounter a problem when using cron.
From what I see there could be 2 possible problems:
If the lines you are running in crontab are (and only those):
home/server/startup/stop.sh
home/server/startup/start.sh
then you are missing the time part of the line. If you want to run your program only once on boot you can run:
#reboot home/server/startup/start.sh
You are not giving the full path to your program (possibly you are just missing a / in the begging). Try running
* * * * * /home/server/startup/start.sh
or
#reboot /home/server/startup/start.sh
If these don't work I recommend you try the following to troubleshoot the issue:
Run the command using sh in the cron:
* * * * * /bin/sh /home/server/startup/start.sh
Try redirecting the stdout and stderr of your command to a file and see if any errors occur

How to make crontab run new version of my script

I have currently running python script on debian system. Now because of some reasons I changed this script and updated cron, but nothing has changed. Also, I tried to save this cron in different file and create new cron - line with job appears, but script doesn't work.
CRON[22310] (root) CMD ( /usr/bin/python /home/radmin/test/test.py)
from /etc/crontab for new script:
*/1 * * * * root /usr/bin/python /home/radmin/test/test.py
for old script:
*/1 * * * * root python /home/radmin/base.py
Script runs correctly without cron.
Tried restarting and reloading cron.
It looks like cron dosen't recognize the root command you add.
try instead opening cron using sudo crontab -e and then add your code:
*/1 * * * * /usr/bin/python /home/radmin/test/test.py
by opening it up with sudo it will add it to the root user cron jobs.
Problem was in python code. Crontab is okay. I'm using python lib "requests" and there is a method to get post request content - ".text", so this method doesn't want to work in cron (empty error logs while running) (still don't know why). So changing .text to .content solved this issue.

How to reboot via cron on scheduled basis. Ubuntu 14.04

I have a very simple script that works from the command line.
#!/bin/bash
reboot
When I put a call to execute the script into root users crontab -e using the following format it does not run. It does run the first two commands, just that last one is giving me grief. I have no MTA installed as I do not need it.
*/10 * * * * service jwtpay restart
0 3 * * * bash /root/backup/mongo.backup.s3.sh kickass /root/backup >/dev/null 2>&1
0 */3 * * * bash /root/reboot.sh >/dev/null 2>&1
What am I missing?
Maybe the script is not executable... Since you use root's crontab why call the binary via a script and not the binary itself? Use the full path to the binary. It may vary on your system. Find out where it is with which reboot.
0 */3 * * * /sbin/reboot
Don't forget to restart the cron daemon, after changeing the crontab.

crontab being saved in tmp/ in debian

I'm trying to make a crontab with crontab -e, but it saves it in tmp/crontab.FTt6nI/crontab
the crons don't work so I guess that's the problem. But I don't understand why.
type:
crontab -l
to show list of crontab, your newly added crontab should be on the list. you could set the crontab to email the output to you by > youremail#aaa.com, in this way you can assure the cronjob is already run.
example:
* * * * * /usr/bin/php /home/username/public_html/cron.php > aaa#aaa.com
make sure the crond is running:
/etc/init.d/crond status
if it down, start it (centos/rhel):
/etc/init.d/crond start
debian/ubuntu:
/etc/init.d/cron start
hope that help.

Resources