The bot on this forum considers my thread to be a duplicate. However, the solution that is proposed does not answer the main question: how, USING A VARIABLE to output the date or the output of any other command from the shell. I can output the date without using a variable easily. But how do this with use a variable?
It is not possible to enter the current date in a variable in the crontab and display it in the name of the log file.
Wrote this:
SHELL=/usr/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/sy
HOME=/home/user/
NOW=`date '+%Y-%m-%d'`
/1 * * * cd /work/current && nice -n 15 php app/console debug:container >> /www/log/cron/test${NOW}.log
I tried this too:
*/1 * * * * cd /work/current && nice -n 15 php app/console debug >> /www/log/cron/_test_${$NOW}.log
And I tried so:
*/1 * * * * cd /work/current && nice -n 15 php app/console debug >> /www/log/cron/_test_"${NOW}".log
But it still doesn't work.
Or it outputs like this:
__test_`date '\''+\%Y-\%m-\%d'\''`.log
or cron displays an error in the log:
ambiguous redirect
%
, they need to be escaped. – rathier Dec 12 '23 at 14:18cd
andphp
commands too. A script is easier to store and track in a source code control system than most crontab files. – Sotto Voce Dec 12 '23 at 14:29NOW=`date '+%Y-%m-%d'`
– Chris Davies Dec 12 '23 at 22:43date '+\%Y-\%Y-\%m-\%d'
.log. But I need it to be in a variable. Like this: NOW=date '+%Y-%m-%d' it doesn't work. Nor does it work in the following way: NOW=$(date '+%Y-%m-%d), and in the following way: NOW=date '+%Y-%m-%d', and in the following way: NOW=date '+\%Y-\%m-\%d'
. So the question is more about how exactly to enter this construct into a variable and how to pass this variable to cron. – sivsoft Dec 13 '23 at 08:55