1

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.

Cronie
  • 11

1 Answers1

0

Jobs run through cron, or systemd startup scripts aren't run in the same runtime environment that you have on your desktop. systemd startup scripts are run as root. None of your PATH changes, or other environment variable settings are automatically propagated to your cron job. For example, there's no $DISPLAY, so GUI programs need special treatment (read man xhost).

One can set environment variables for all one's cron jobs in the crontab file Read man 5 crontab.

Look at the results of echo "=== id ===";id;echo "=== set ===";set;echo "=== env ===";env | sort;echo "=== alias ===";alias in each of your environments.

Since the command part of the crontab line is, by default, interpreted by /bin/sh, which has a simpler syntax than /bin/bash, I recommend having command be a call to a bash script (executable, mounted, starts with #!/bin/bash) which sets up the environment, then calls the desired program.

waltinator
  • 37,856