Reputation: 182
I'm trying to setup a Cron job on my system by adding the following line
17 12 * * * Rscript ~/path/to/file/script.R > ~/output_`date +\%d\%m\%y`.txt 2>&1
yet, I cannot see the file the output is being written to. I've consulted the following answers, but to no avail:
Why did my crontab not trigger
When I run the following command on the terminal:
Rscript ~/path/to/file/script.R > ~/output_`date +\%d\%m\%y`.txt 2>&1
I get the output file as expected. I also added the following line to crontab:
* * * * * echo hi > ~/output.txt 2>&1
and it works just fine. I'm not sure what is wrong with the first command. Any help would be appreciated. Thanks.
Upvotes: 0
Views: 1879
Reputation: 1290
I fixed this by replacing Rscript
in my crontab with /usr/local/bin/Rscript
(or wherever your Rscript is located - do which Rscript
to find out).
Upvotes: 2
Reputation: 3137
Try Below trick, Create one script script.sh like below -
cat script.sh
Rscript ~/path/to/file/script.R > ~/output_$(date +\%d\%m\%y).txt 2>&1
And then create below entry in crontab.
17 12 * * * /bin/bash /path/to/script.sh
Upvotes: 1