I have this in my crontab mysqldump
to make a backup of my bd:
0 5 * * mon,wed,thu,fri root mysqldump test > /var/backups/databases/test_$( date '+%F_%H:%M:%S' ).sql
And I am seeing that no backup of said DB has been made, I have gone to /var/mail/root
and I have found crontab errors that I have received as alerts, specifically:
To: root
Subject: Cron <xxxr> mysqldump test > /var/backups/databases/database_test_$( date '+
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: xxx
X-Cron-Env: xxx
X-Cron-Env: xxx
X-Cron-Env: xxx
Message-Id: xxx
Date: Mon, 12 Apr 2021 03:00:01 +0000 (UTC)
/bin/sh: 1: Syntax error: Unterminated quoted string
Syntax error: Unterminated quoted string
So, because of the error it gives me, I interpret that it doesn't finish reading the line and cuts the script when it goes, data ' +...
that's why it gives me a syntax error. But of course, it doesn't make any apparent sense, does it? Why would I cut there?
In fact I have tested the script by hand and it works fine.
Update
I have these environments in the crontab:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
Translated from the crontab manual :
That's why it cuts the line, so you have to escape the date format: