user dietpi/root crontab not working

I added a few cronjobs in dietpi user crontab (with ‘crontab -e’)

15 5 * * * /usr/bin/touch /mnt/backup/magiatiko/test-$(date +%F)
16 5 * * * /usr/bin/scp root@magiatiko:/tmp/backup-magiatiko-$(date +%F).tar.gz /mnt/backup/magiatiko/
20 5 * * * /usr/bin/find /mnt/backup/magiatiko -type f -mtime +30 -exec rm -f {} \;
21 5 * * * /usr/bin/find /mnt/backup/kodi -type f -mtime +30 -exec rm -f {} \;

I added the first one to verify that it indeed works, but no file is created.
All commands run successfully when run from shell as user dietpi.
Am I missing something?

Did you tried to place inside root user crontab?

No, because I don’t want to run the commands as root user.
Doesn’t the dietpi user crontab work?

it was more for testing purposes to check if it’s working at all

It is not working for root either.
I added the first job (with touch) and it was not created.

ok I created a cron job for this night on one of my test RPi systems. let’s see how it’s going

Hi trendy

I did a test entry on my crontab for user dietpi

dietpi@DietPi3:~$ crontab -l
00 00 * * * date > /tmp/date.log
dietpi@DietPi3:~$

And for me it was working fine. The file was created at Midnight as expected

root@DietPi3:/tmp# ls -la |grep date.log
-rw-r--r--  1 dietpi dietpi   30 Jul 22 00:00 date.log
root@DietPi3:/tmp# cat date.log
Wed Jul 22 00:00:01 CEST 2020
root@DietPi3:/tmp#

Your date command worked for me as well.
I think there is something wrong with the special characters in my commands, therefore let’s mark it as solved. Thank you for the tip!

Just an idea. Place you commands into a script and let the script be executed by crontab.

I was trying to avoid that, not to have many different scripts. If I fail to escape the special characters correctly, I’ll resort to that.

For anyone that might be interested:

05 5 * * * /usr/bin/scp 'root@magiatiko:/tmp/backup-magiatiko-'$(date +\%F)'.tar.gz /mnt/backup/magiatiko/'

Escaping % did the trick. The rest was included in single quotes.