I am wanting to create backups of a Minecraft server I administrate. I wrote a bash script that performs a ftp wget backup of the server files to a new folder.
Here is that script:
TIMESTAMP=$(/bin/date +%Y-%m-%d_%H:%M)
/bin/mkdir /disks/Media/MC\ Server\ Backups/backup/$TIMESTAMP -p
cd /disks/Media/MC\ Server\ Backups/backup/$TIMESTAMP
/usr/bin/wget -r ftp://$FTP_USER:$FTP_PASS@$FTP_ADDR// -l 0 -nH
The variables are the ftp server connection details, and are omitted for obvious reasons. When I run the script on it's own,it works flawlessly. My issue is getting it to work as a cron job, so backups are automatic. From a terminal running on /
, I type crontab -e
.
I use gedit to add the cron job:
1 4 * * * /disks/Media/MC\ Server\ Backups/ftp-backup.sh
So it should run at 4:01 AM every day, but it does not. Is the issue that the script is kept on a mounted external NTFS drive? I've looked to see if the cron job created the backup folder somewhere else, but I do not see another one.
I have added #!/bin/sh
to the beginning of the script. I have also run chmod-x on the script itself. I have also tried two different formats for running my script:
15 25 * * * /disks/Media/MC\ Server\ Backups/ftp-backup.sh &>/tmp/cronout.log
and
15 25 * * * /bin/sh /disks/Media/MC\ Server\ Backups/ftp-backup.sh &>/tmp/cronout.log
The last part is supposed to log any issues, yet these files are never created at all.
I have been testing cron by setting the jobs to be a few minutes into the future.
When seeing if cron is running with this command: systemctl status cron
, I get the following output:
● cron.service - Regular background program processing daemon
Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
Active: failed (Result: signal) since Sun 2019-12-22 12:20:27 EST; 2 weeks 3 days ago
Docs: man:cron(8)
Process: 1081 ExecStart=/usr/sbin/cron -f $EXTRA_OPTS (code=killed, signal=KILL)
Main PID: 1081 (code=killed, signal=KILL)
Dec 22 11:24:38 jlcarveth-MS-7A72 cron[1081]: (CRON) INFO (Running @reboot jobs)
Dec 22 11:30:01 jlcarveth-MS-7A72 CRON[3975]: pam_unix(cron:session): session opened for user jlcarveth by (ui
Dec 22 11:30:01 jlcarveth-MS-7A72 CRON[3976]: (jlcarveth) CMD (/bin/bash /disks/Media/MC\ Server\ Backups/ftp-
Dec 22 12:11:44 jlcarveth-MS-7A72 CRON[3975]: (CRON) info (No MTA installed, discarding output)
Dec 22 12:11:44 jlcarveth-MS-7A72 CRON[3975]: pam_unix(cron:session): session closed for user jlcarveth
Dec 22 12:17:01 jlcarveth-MS-7A72 CRON[11533]: pam_unix(cron:session): session opened for user root by (uid=0)
Dec 22 12:17:01 jlcarveth-MS-7A72 CRON[11534]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Dec 22 12:17:01 jlcarveth-MS-7A72 CRON[11533]: pam_unix(cron:session): session closed for user root
Dec 22 12:20:27 jlcarveth-MS-7A72 systemd[1]: cron.service: Main process exited, code=killed, status=9/KILL
Dec 22 12:20:27 jlcarveth-MS-7A72 systemd[1]: cron.service: Failed with result 'signal'.
From what I can tell, cron isn't running correctly, but IDK how to rectify that.
Not sure what I changed, but the following seems to run:
50 16 * * * /disks/Media/MC\ Server\ Backups/ftp-backup.sh
1 4 * * * /bin/bash /path/to/file
?#!/bin/bash
. Running Ubuntu 18.04. Do not know exactly what you mean, the script runs if I just type it's path in the terminal. 3rd Question: yes I tested that too, and never say any backup files made/bin/sh
. Try in your crontab add theSHELL=/bin/bash
line at the beginning to see if works.