Skip to content

herrersystem/crog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crog

PyPI PyPI PyPI

Generate cronjobs for python scripts.

Installation

pip install crog

Get started

Crog class

from crog.crog import Crog

Class accept 6 arguments:

  • name (str): name of cronjobs file.
  • minute (str or int): number of minutes between each time the cron job runs, or the minute of each hour on which you wish to run the cron job.
  • hour (str or int): number of hours between each time the cron job runs, or the hour of each day on which you wish to run the cron job.
  • month (str or int): number of months between each time the cron job runs, or the month of the year in which you wish to run the cron job. (default: '*')
  • week_day (str or int): number of days between each time the cron job runs, or the day of the month on which you wish to run the cron job. (default: '*')
  • month_day (str or int): days of the week on which you wish to run the cron job. (default: '*')

Example say_hello.py

#!/usr/bin/env python3

import sys
from crog.crog import Crog

cron = Crog('helloworld', 15, 0) ## all days at 00:15
cron.user = 'herrer'

## Each lists represent 1 cronjob line with these parameters.
params = [['gerard'], ['ted']]


@cron.load(params=params)
## @cron.load() without params. 
def say_hello():
	if len(sys.argv) > 1:
		name = sys.argv[1]
		print('Hello %s'%name)

	else:
		print('Usage: %s <name>' % sys.argv[0])


if __name__ == '__main__':
	say_hello()

First execution

First execution create cronjobs file.

root@comuter# python say_hello.py
[crop] config file helloworld was created.
15 0 * * * herrer /root/app/say_hello.py gerard
15 0 * * * herrer /root/app/say_hello.py ted

Step to use

  • Declare Crog object.
  • Define user right for execution (default: 'root').
  • Define params if script accept arguments (optionnal).
  • Decorate main function with 'Crog.load' decorator.
  • Execute your script first time (with root) to generate cronjobs config file.

Update cronjobs

Just change Crog object declaration and execute one more time your script.

About

Generate cronjobs for python scripts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages