I have a simple backup script with this line to come up with a name for the backup:
backup=$(/bin/date +'%Y-%m-%d_%H:%M_%S')_$(hostname).gz
It works great when I run it under the root user. Unfortunately when I set it to run as a cronjob, the $(hostname) part is always empty and I don't get the hostname. Why isn't it working, and how can I get the hostname in a cron job?
I'm running ubuntu 18.04
/bin/date
with an explicit path: IsPATH
set correctly to containhostname
? – DonHolgo Sep 04 '19 at 14:40%
is special in crontabs, and must be escaped. See e.g. How can I execute `date` inside of a cron tab job? – Kusalananda Sep 04 '19 at 15:04