https://github.com/litencatt/crntb
Crontab format translation tool.
https://github.com/litencatt/crntb
crontab ruby
Last synced: 5 months ago
JSON representation
Crontab format translation tool.
- Host: GitHub
- URL: https://github.com/litencatt/crntb
- Owner: litencatt
- License: mit
- Created: 2018-06-04T12:09:33.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-07-09T20:25:24.000Z (almost 5 years ago)
- Last Synced: 2025-11-30T18:50:30.195Z (7 months ago)
- Topics: crontab, ruby
- Language: Ruby
- Homepage:
- Size: 79.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Inspired by http://crontab.homecoded.com/
Convert crontab lines to other format.
## Install
```
$ git clone https://github.com/litencatt/crntb
$ cd /path/to/crntb
$ bundle install --path vendor/bundle
```
## Usage
Convert a line.
### Hash
`.to_h`
```rb
$ bin/console
[1] pry(main)> Crntb.parse("* * * * * foo.sh").to_h
=> {:minute=>"*", :hour=>"*", :day_of_month=>"*", :month=>"*", :day_of_week=>"*", :command=>"foo.sh"}
```
### JSON
`.to_json`
```
[1] pry(main)> Crntb.parse("* * * * * foo.sh").to_json
=> "{\"minute\":\"*\",\"hour\":\"*\",\"day_of_month\":\"*\",\"month\":\"*\",\"day_of_week\":\"*\",\"command\":\"foo.sh\"}"
```
### To Chef cron resource DSL
`to_chef`
```
[2] pry(main)> puts Crntb.parse("* * * * * foo.sh").to_chef
cron 'exec_foo.sh' do
minute "*"
hour "*"
day "*"
month "*"
weekday "*"
command "foo.sh"
end
=> nil
```
### To Whenever DSL
`.to_whenever`
```
[3] pry(main)> puts Crntb.parse("* * * * * foo.sh").to_whenever
every '* * * * *' do
command "foo.sh"
end
=> nil
```
### To English
`.to_eng`
```
[2] pry(main)> Crntb.parse("* * * * * foo.sh").to_eng
=> "every minute of every hour of every day, Execute \"foo.sh\""
```
### To Markdown
`.to_md`
```
[3] pry(main)> Crntb.parse("* * * * * foo.sh").to_md
=> "## Summary\nevery minute of every hour of every day, Execute \"foo.sh\"\n\n### Command\n```\nfoo.sh\n```\n### Fields\n\n| fields | minute | hour |day_of_month | month | day_of_week |\n| --- | :---: | :---: | :---: | :---: | :---: |\n| value | * | * | * | * | * |\n"
```
---
## Summary
every minute of every hour of every day, Execute "foo.sh"
### Command
```
foo.sh
```
### Fields
| fields | minute | hour |day_of_month | month | day_of_week |
| --- | :---: | :---: | :---: | :---: | :---: |
| value | * | * | * | * | * |
---
### Convert crontabs written in a file.
```rb
$ bin/console
[1] pry(main)> Crntb.parse_file("./sample.cron").map{|e| pp e.to_json }
```