I have a very simple cron task I want to run hourly, its a bash script that I want to store the output of in a daily log file. The crontab looks like:
[srvc_user]$ crontab -l
15 * * * * /path/to/script 2&>1 >> /path/to/logs/script_$(date +"%Y%m%d").log
What I'm seeing from the syslog is that the task is running hourly as scheduled but no new log files are being produced:
[root]# journalctl -u crond.service -g script
Aug 17 04:15:02 myhost.server.com CROND[3827797]: (srvc_user) CMD (/path/to/script 2&>1 >> /path/to/logs/script_$(date +").log)
Aug 17 05:15:01 myhost.server.com CROND[3742589]: (srvc_user) CMD (/path/to/script 2&>1 >> /path/to/logs/script_$(date +").log)
Aug 17 06:15:01 myhost.server.com CROND[3655718]: (srvc_user) CMD (/path/to/script 2&>1 >> /path/to/logs/script_$(date +").log)
Aug 17 07:15:01 myhost.server.com CROND[3567401]: (srvc_user) CMD (/path/to/script 2&>1 >> /path/to/logs/script_$(date +").log)
Aug 17 08:15:01 myhost.server.com CROND[3479789]: (srvc_user) CMD (/path/to/script 2&>1 >> /path/to/logs/script_$(date +").log)
Aug 17 09:15:01 myhost.server.com CROND[3386346]: (srvc_user) CMD (/path/to/script 2&>1 >> /path/to/logs/script_$(date +").log)
[srvc_user]$ ls /path/to/logs
## No new files here!
I can run the script on its own as the crontab user with no problems; I can also copy-paste the full crontab line and it runs the script and pipes the output to the logfile as expected:
[srvc_user]$ /path/to/script
# Normal output here!
[srvc_user]$ /path/to/script 2&>1 >> /path/to/logs/script_$(date +"%Y%m%d").log
[srvc_user]$ ls /path/to/logs
# New files here!
I also verified that the crontab user has access to the log folder:
[srvc_user]$ ls /path/to
drwxr-xr-x 2 srvc_user users 4096 Aug 17 01:26 logs
# other files...
Not sure what to look at next.