I am a novice ... I will just get that right up front. I have a simple Ubuntu 20.04 LTS server used only as a minecraft server.
The crontab is giving me some problems
*/10 * * * * screen -S minecraft -p 0 -X stuff "save-all^M"
@reboot /home/minecraft/startserver.sh
@daily find /home/minecraft/backup/* -mtime +6 -type f -delete
@daily zip -9 -r --exclude=*backup* --exclude=*web* --exclude=*crash-reports* --exclude=*lost+found* /home/minecraft/backup/$(date +"%Y.%m.%d %I.%M %P").zip /home/minecraft
The first line works, but the @daily and @reboot do not work at all. ALL the commands work from the terminal without error.
Please help me understand this, I am not experienced with linux and I am trying to figure this out. I am aware that some people might think this would be better handled with systemd, but I am too new to figure that out yet and I don't want to install a script I can't repair.
Why is the crontab failing these lines? I don't think it is permissions. Please help me debug this
Thanks for your time
EDIT: OK, after digging around, the issue with the startserver script was within the script itself and not the crontab. I found out I need to have the -d
flag for the screen command in crontab.
The zip command is working, but I can't figure out what escape code to use to add spaces in the date backup/$(date +"\%Y.\%m.\%d \%I.\%M \%P").zip
Using a slash \
or using " "
do not work. If anyone knows how to escape a space with creating zip files, please let me know.
I was told in the comments to use the proper format for editing the post. I don't know what that means, this is my first post.
%
characters (...date +"\%Y.\%m.\%d \%I.\%M \%P"...
) (see here), and should probably also quote the wildcards in thezip
command (e.g.--exclude="*backup*"
) (but not in thefind
command). Beyond that, I'd log output & errors from the commands by adding something like>>/tmp/minecraftserver.log 2>&1
to each line (but with a different filename for each one), then checking those log files to see if they give an indication what's happening.date
to tell it there's a space in the argument (rather than between arguments), and you also have to put double-quotes around the$( )
thing to tell the shell not to word-split the output it gets. It's probably cleanest to double-quote the entire filepath:... "/home/minecraft/backup/$(date +"\%Y.\%m.\%d \%I.\%M \%P").zip" ...
. BTW, I second waltinator's recommendation to put this in a script (and remove those escapes), and just have the cron entry run the script.