Ubuntu 18.04 running as guest on MacOS 10.14.3. Hypervisor: VMWare Fusion 10
Objective: Every minute, append the date/time into a file
Status: Script runs every minute, inserting a blank new line into the text file. The date is not included. That is the problem
When the script is run from the command line, using the same account as the account on the crontab, the date is added to the file, no problem.
Apparent Problem: Echoing date to file works from command line, but same command from cron does not produce date
This is the script that runs every minute in cron.
#!/bin/bash #append_date_to_file.sh target_file='/home/dan/timestamps' echo $(date) >> $target_file
This is the cron entry
crontab -e PATH=/bin/bash: * * * * * /home/dan/append_date_to_file.sh
RESULTS When running three times from command line, then viewing the target file:
$ cat /home/dan/timestamps Sat Aug 17 18:31:12 CDT 2019 Sat Aug 17 18:31:33 CDT 2019 Sat Aug 17 18:31:34 CDT 2019
Then waiting three minutes, to let it run three times in cron, then viewing the target file: (same as above, except three new blank lines after the dates.)
Problems Considered .. file permissions. To address this, here is the file as it is listed with permissions and owner:group:
-rwxrwxrwx 1 dan dan 157 Aug 17 18:43 timestamps*
.. Script not running in cron. Resolved: script is proven to run by the fact that modified time on the file changes at the start of every minute and the file gets a new blank line at the same time.
I cannot think of an explanation for the date not being added to the file when the script is run by cron instead of the command line.
Any ideas would be appreciated.