How to use cron.d file when using Ubuntu - cron

I have a backup script that I can run successfully manually as root
backup perform --trigger confluence --config-file /etc/backup/config.rb --log-path=/var/log > /dev/null
In the /etc/cron.d folder I have file confluence_backup with the following contents
# Crontab for confluence_backup managed by Chef. Changes will be overwritten.
0 0 * * * root backup perform --trigger confluence --config-file /etc/backup/config.rb --log-path=/var/log > /dev/null
For some reason this backup script will not run. I don't see messages in /var/log/backup or in syslog for that matter. I tried restart of cron service but still the job does not run.
Why is the script not running?

First, have you confirmed that the executable 'backup' is in the root user's PATH variable?

Related

Run cron job hourly

I use let's encrypt for getting certificates and I want to setup renewal for certificates.
So, I decided to check if cron works fine.
I created three file in daily.hourly folder:
test-h:
/sbin/ifconfig >/home/bitnami/ipt
test-h2:
#!/bin/bash
/sbin/ifconfig > /home/bitnami/ipt2
test-h3.sh:
#!/bin/bash
/sbin/ifconfig >/home/bitnami/ipt3
But, I don't see my files in home directory. How to properly use cron.daily?
PS. The cron servive is started, I checked.
I restarted it also just to make sure that changes is applied.
The crontab file contains record for cron.hourly:
17 * * * * root cd / && run-parts --report /etc/cron.hourly
I am not linux guy, so, if it possible get me detailed answer please.
The problem is you didn't chmod +x your scripts. That's needed to make them executable.

Cron runs .sh file without any result

I just made a little .sh script which just downloads a .txt file from the web. I want this to be run every two minutes.
getfeed.sh:
#!/bin/sh
FILENAME=`date +"%Y%m%d%H%M"`.txt
cd feedhistory
/usr/bin/wget -O $FILENAME http://www.example.com/link/to/file.txt
Crontab:
*/2 * * * * /bin/sh /var/www/src/cron/getfeed.sh
Syslog entry:
Sep 24 XX:XX:XX servername CRON[10451]: (root) CMD (/bin/sh /var/www/src/cron/getfeed.sh)
The .sh file itself works fine and the syslog shows Cron is doing something with the file. But there is nothing downloaded...
Thanks in advance
Henry
Usually cron runs the command in the user's home directory. Your cron job doesn't specify a user, so it will be executed by root.
As your $FILENAME does not contain a path, the file should be downloaded to the /root/ directory of your system.
If you want them to be somewhere else, you should either set a user for the cron job, or set an absolute path for the download destination.

cronjob not running script inside another user bin folder

I'm trying to have root run a script sitting inside another user's bin folder (say 'john'). The script itself is owned by root and chmoded 774.
I can launch the script without any issue from the command line.
Via cron, it does not get started. I can't understand why.
Here is the content if i crontab -e while logged in as root.
# daily backup
15 2 * * * php -q /home/john/bin/backup
My server is a Red Hat Enterprise Linux Server release 6.5 (Santiago)
Perhaps php is not in the default PATH, such as in /usr/local/bin rather than /usr/bin or /bin.
Always redirect the output of both stdout and stderr, otherwise the default has traditionally been to send a message via /usr/bin/mail, and you probably don't want to get an email each time the job runs.
When you revise your crontab (i.e. "/usr/local/bin/php -q /home/john/bin/backup > /tmp/crontest.txt 2>&1") you can then see if any error messages are being logged.

Synology - Cron job

I'm trying to make cron jobs or task schduler working, but I can not figure out why my script is not taken in consideration.
I'm trying to simply archive a folder with:
tar -cvf /volume1/NetBackup/Backups/Monday.tgz /volume1/NetBackup/Backups/ns3268116.ovh.net/
Each time the script starts working but cannot achieve the work. Either with task scheduler or crontab, a file Monday.tgz is created in folder /volume1/NetBackup/Backups/, but this file is only 1024 bytes.
Synology Cron is really fussy.
Here are my own personal notes for Synology DS413j, DSM 5.2:
Hand edit /etc/crontab as root, crontab -e isn't available
Ensure you use tabs not spaces to separate the columns
Your crontab changes may not survive a reboot if there are syntax problems
The who column in crontab may not be reliable. Use root in the who column and /bin/su -c '<command>' <username> to run as another other user
remember that it uses ash not bash so check for bashisms, e.g use >> /path/to/logfile 2>&1' not&>> /path/to/logfile`
It doesn't support 'MAILTO='
you need to restart crond synoservicectl --reload crond for the new crontab to take effect
You may try adding some diagnostics to it. For instance:
Add MAILTO into the crontab file (on top of crontab -e) to receive cron errors by email:
MAILTO=username#domain.com
Redirect output of your tar command to the file:
your command > ~/log.txt 2>&1
Check cron log and look for anomalies. For instance (it may depend on your configuration):
/var/log/cron.log
You may also try searching through /var/log/messages at the time of your cron job.
Is volume1 a resource on remote host? If yes, it is worth checking this part of the system.
I agree about the really nagging nature of Crontab on Synology Linux OSs.
I would certainly suggest to create de desired job as a .sh shell script and call it via CRON task inserted by using the GUI, as suggested here.
As for today (March 2017) is the best method I have found, since working with crontab via CLI is nearly a pain.

crontab #reboot does not execute bash script when server is rebooted

I'm using #reboot ~/www/example.com/bin/server in my user's crontab...but when I reboot the server, the web server (this script) does not come up. (script works fine from command line).
My guess is the /home/user directory has not been mounted yet...does anyone know if its possible to get a script to run out of a home directory using this crontab #reboot method?
If you think /home/user hasn't been mounted (or some required systems aren't running) yet, in your crontab line, you can always wait before executing a command like:
#reboot sleep 60; /home/user/www/example.com/bin/server
It should definitely be due to the environment scenarios as given in comments. Try the following and check once by doing a reboot
#reboot (date > /tmp/date-check.txt)
To be sure cron is able to run the jobs.
My problem was that the crontab did not have a full environment. I made the script it was pointing to source my .bashrc.
#reboot /home/user/www/example.com/bin/server
./server does . /home/user/.bashrc to get a working environment.
In Ubuntu if you are using the Home Directory Encryption feature turned on then #reboot in your crontab file won't work as the file system is still encrypted when the system is starting up and cron runs its #reboot jobs.
Your options are to place your files in an unencrypted location (/usr/local/bin or something?) or disable Home Directory encryption on your home directory.

Resources