问题
I am trying to schedule a cronjob to execute an R Script in a linux server. I have achieved to type the commands in the server manually and it works. To do so i have to type the following commands:
- root@debian:~# cd /home/script2
- root@debian:/home/script2# Rscript scriptSecos.R
How can i specify a cronjob that will execute the previous commands, once a day?
Thank you.
回答1:
The following cron job will run Rscript scriptSecos.R
from the path /home/script2
, once a day, at 0:00 (midnight).
0 0 * * * cd /home/script2; Rscript scriptSecos.R >/dev/null 2>&1
If you want to save the output of the script to a file, change >/dev/null
with >/path/to/file
.
You can copy and paste this cronjob in your crontab file (You can open the file by using command crontab –e
)
回答2:
The following site provides useful reference information for crontab
http://www.adminschoice.com/crontab-quick-reference
With your example, the following will run the job at 3 am everyday.
00 03 * * * Rscript /home/script2/scriptSecos.R
回答3:
add cron as below.
eg:
15 23 * * * Rscript /home/script2/scriptSecos.R >/dev/null 2>&1
you have to mention running script type.Then allow cron logs and check its running or not
来源:https://stackoverflow.com/questions/30905934/how-to-schedule-an-r-script-cronjob-in-a-linux-server