cron_add: Make a simple cron job

Description Usage Arguments Examples

View source: R/cron_add.R

Description

Generate a cron job, and pass it to crontab.

The goal is to be able to translate simple English statements of intent to the actual cron statement that could execute that intent. For example,

"I want to run a job daily at 7AM."

is simply

cron_add(<command>, "daily", at="7AM")

Another example, "I want to run a job on the 15th of every month."

is

cron_add(<command>, "monthly", days_of_month="15th")

Usage

1
2
3
4
5
cron_add(command, frequency = "daily", at, days_of_month, days_of_week,
  months, id, tags = "", description = "", dry_run = FALSE, user = "")

cronjob(command, frequency = "daily", at, days_of_month, days_of_week, months,
  id, tags = "", description = "", dry_run = FALSE, user = "")

Arguments

command

A command to execute.

frequency

A character string equal to one of "minutely", "hourly", "daily", "monthly", or "yearly". Or any complex cron schedule - see the examples.

at

The actual time of day at which to execute the command. When unspecified, we default to "3AM", when the command is to be run less frequently than "hourly".

days_of_month

Optional; the day(s) of the month on which we execute the command.

days_of_week

Optional; the day(s) of the week on which we execute the command.

months

Optional; the month(s) of the year on which we execute the command.

id

An id, or name, to give to the cronjob task, for easier revision in the future.

tags

A set of tags, used for easy listing and retrieval of cron jobs.

description

A short description of the job, and its purpose.

dry_run

Boolean; if TRUE we do not submit the cron job; instead we return the parsed text that would be submitted as a cron job.

user

The user whose cron jobs we wish to examine.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
## Not run: 
f <- system.file(package = "cronR", "extdata", "helloworld.R")
cmd <- cron_rscript(f)
cmd

cron_add(command = cmd, frequency = 'minutely', 
  id = 'test1', description = 'My process 1', tags = c('lab', 'xyz'))
cron_add(command = cmd, frequency = 'daily', at='7AM', id = 'test2')
cron_njobs()

cron_ls()
cron_clear(ask=FALSE)
cron_ls()

cmd <- cron_rscript(f, rscript_args = c("productx", "arg2", "123"))
cmd
cron_add(cmd, frequency = 'minutely', id = 'job1', description = 'Customers')
cron_add(cmd, frequency = 'hourly', id = 'job2', description = 'Weather')
cron_add(cmd, frequency = 'hourly', id = 'job3', days_of_week = c(1, 2))
cron_add(cmd, frequency = 'hourly', id = 'job4', at = '00:20', days_of_week = c(1, 2))
cron_add(cmd, frequency = 'daily', id = 'job5', at = '14:20')
cron_add(cmd, frequency = 'daily', id = 'job6', at = '14:20', days_of_week = c(0, 3, 5))
cron_add(cmd, frequency = 'daily', id = 'job7', at = '23:59', days_of_month = c(1, 30))
cron_add(cmd, frequency = 'monthly', id = 'job8', at = '10:30', 
  days_of_month = 'first', days_of_week = '*')
cron_add(cmd, frequency = '@reboot', id = 'job9', description = 'Good morning')
cron_add(cmd, frequency = '*/15 * * * *', id = 'job10', description = 'Every 15 min')   
cron_ls()
cron_clear(ask=FALSE)

## End(Not run)

Example output

[1] "/usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R'  >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1"
Adding cronjob:
---------------

## cronR job
## id:   test1
## tags: lab, xyz
## desc: My process 1
0-59 * * * * /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R'  >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1
Adding cronjob:
---------------

## cronR job
## id:   test2
## tags: 
## desc: 
0 7 * * * /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R'  >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1
There are a total of 2 cronR cron jobs and 0 other cron jobs currently running.
## cronR job
## id:   test1
## tags: lab, xyz
## desc: My process 1
0-59 * * * * /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R'  >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1

## cronR job
## id:   test2
## tags: 
## desc: 
0 7 * * * /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R'  >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1


No cron jobs available for user 'anon'.
[1] "/usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1"
Adding cronjob:
---------------

## cronR job
## id:   job1
## tags: 
## desc: Customers
0-59 * * * * /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1
Adding cronjob:
---------------

## cronR job
## id:   job2
## tags: 
## desc: Weather
0 * * * * /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1
Adding cronjob:
---------------

## cronR job
## id:   job3
## tags: 
## desc: 
0 * * * 1,2 /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1
Adding cronjob:
---------------

## cronR job
## id:   job4
## tags: 
## desc: 
20 * * * 1,2 /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1
Adding cronjob:
---------------

## cronR job
## id:   job5
## tags: 
## desc: 
20 14 * * * /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1
Adding cronjob:
---------------

## cronR job
## id:   job6
## tags: 
## desc: 
20 14 * * 0,3,5 /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1
Adding cronjob:
---------------

## cronR job
## id:   job7
## tags: 
## desc: 
59 23 1,30 * * /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1
Adding cronjob:
---------------

## cronR job
## id:   job8
## tags: 
## desc: 
30 10 1 * 0,1,2,3,4,5,6 /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1
At your own risk: will set the cron schedule as is: '@reboot'
Adding cronjob:
---------------

## cronR job
## id:   job9
## tags: 
## desc: Good morning
@reboot /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1
At your own risk: will set the cron schedule as is: '*/15 * * * *'
Adding cronjob:
---------------

## cronR job
## id:   job10
## tags: 
## desc: Every 15 min
*/15 * * * * /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1
## cronR job
## id:   job1
## tags: 
## desc: Customers
0-59 * * * * /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1

## cronR job
## id:   job2
## tags: 
## desc: Weather
0 * * * * /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1

## cronR job
## id:   job3
## tags: 
## desc: 
0 * * * 1,2 /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1

## cronR job
## id:   job4
## tags: 
## desc: 
20 * * * 1,2 /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1

## cronR job
## id:   job5
## tags: 
## desc: 
20 14 * * * /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1

## cronR job
## id:   job6
## tags: 
## desc: 
20 14 * * 0,3,5 /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1

## cronR job
## id:   job7
## tags: 
## desc: 
59 23 1,30 * * /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1

## cronR job
## id:   job8
## tags: 
## desc: 
30 10 1 * 0,1,2,3,4,5,6 /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1

## cronR job
## id:   job9
## tags: 
## desc: Good morning
@reboot /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1

## cronR job
## id:   job10
## tags: 
## desc: Every 15 min
*/15 * * * * /usr/lib/R/bin/Rscript '/usr/local/lib/R/site-library/cronR/extdata/helloworld.R' productx arg2 123 >> '/usr/local/lib/R/site-library/cronR/extdata/helloworld.log' 2>&1

cronR documentation built on Oct. 23, 2020, 7:13 p.m.