如何每天两次 运行 一个 R 脚本?
How to run a R script twice a day?
我有一个 R 脚本配置为每天上午 10 点通过 cron 运行
library(cronR)
cmd2 = cron_rscript("CargueDiario_RedcapCovid_ODS.R", rscript_log="/home/admonda/R/projects/contagios_covid_santander/log/cargue_diario.log", log_append = T, log_timestamp = T)
cron_add(command = cmd2, frequency = 'daily', at = "10:00" , days_of_week = "*", id = 'FCVREDCAPCOVID_ODS_DIARIO', description = "FCVREDCAPCOVID_ODS_DIARIO")
cron_ls("FCVREDCAPCOVID_ODS_DIARIO")
## cronR job
## id: FCVREDCAPCOVID_ODS_DIARIO
## tags:
## desc: FCVREDCAPCOVID_ODS_DIARIO
0 10 * * 0,1,2,3,4,5,6 /usr/lib/R/bin/Rscript '/home/admonda/R/projects/contagios_covid_santander/CargueDiario_RedcapCovid_ODS.R' >> '/home/admonda/R/projects/contagios_covid_santander/log/cargue_diario.log' 2>&1
现在我需要对其进行更改,使其每天 运行 两次(10:00 和 22:00)。我已经从 CRON 中删除了它,我想确保这是正确的新命令:
cron_add(command = cmd2, frequency = 'daily', at = c("10:00","22:00") , days_of_week = "*", id = 'FCVREDCAPCOVID_ODS_DIARIO', description = "FCVREDCAPCOVID_ODS_DIARIO")
您仍然可以使用原来的线路,只需将 10
更改为 10,22
。
0 10,22 * * * /usr/lib/R/bin/Rscript '/home/admonda/R/projects/contagios_covid_santander/CargueDiario_RedcapCovid_ODS.R' >> '/home/admonda/R/projects/contagios_covid_santander/log/cargue_diario.log' 2>&1 >/dev/null 2>&1
cron_add(command = cmd2, frequency = 'daily', at = 'c(10,22)', days_of_week = '*', id = '...', description = '...')
或者只使用 cron 表达式:
cron_add(cmd, frequency = '0 10,22 * * *', id = '...', description = '...')
来源:https://www.rdocumentation.org/packages/cronR/versions/0.4.2/topics/cron_add
我有一个 R 脚本配置为每天上午 10 点通过 cron 运行
library(cronR)
cmd2 = cron_rscript("CargueDiario_RedcapCovid_ODS.R", rscript_log="/home/admonda/R/projects/contagios_covid_santander/log/cargue_diario.log", log_append = T, log_timestamp = T)
cron_add(command = cmd2, frequency = 'daily', at = "10:00" , days_of_week = "*", id = 'FCVREDCAPCOVID_ODS_DIARIO', description = "FCVREDCAPCOVID_ODS_DIARIO")
cron_ls("FCVREDCAPCOVID_ODS_DIARIO")
## cronR job
## id: FCVREDCAPCOVID_ODS_DIARIO
## tags:
## desc: FCVREDCAPCOVID_ODS_DIARIO
0 10 * * 0,1,2,3,4,5,6 /usr/lib/R/bin/Rscript '/home/admonda/R/projects/contagios_covid_santander/CargueDiario_RedcapCovid_ODS.R' >> '/home/admonda/R/projects/contagios_covid_santander/log/cargue_diario.log' 2>&1
现在我需要对其进行更改,使其每天 运行 两次(10:00 和 22:00)。我已经从 CRON 中删除了它,我想确保这是正确的新命令:
cron_add(command = cmd2, frequency = 'daily', at = c("10:00","22:00") , days_of_week = "*", id = 'FCVREDCAPCOVID_ODS_DIARIO', description = "FCVREDCAPCOVID_ODS_DIARIO")
您仍然可以使用原来的线路,只需将 10
更改为 10,22
。
0 10,22 * * * /usr/lib/R/bin/Rscript '/home/admonda/R/projects/contagios_covid_santander/CargueDiario_RedcapCovid_ODS.R' >> '/home/admonda/R/projects/contagios_covid_santander/log/cargue_diario.log' 2>&1 >/dev/null 2>&1
cron_add(command = cmd2, frequency = 'daily', at = 'c(10,22)', days_of_week = '*', id = '...', description = '...')
或者只使用 cron 表达式:
cron_add(cmd, frequency = '0 10,22 * * *', id = '...', description = '...')
来源:https://www.rdocumentation.org/packages/cronR/versions/0.4.2/topics/cron_add