cronjoborganize 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cronjoborganize-0.1.1/LICENSE +21 -0
- cronjoborganize-0.1.1/PKG-INFO +35 -0
- cronjoborganize-0.1.1/README.md +25 -0
- cronjoborganize-0.1.1/pyproject.toml +20 -0
- cronjoborganize-0.1.1/setup.cfg +4 -0
- cronjoborganize-0.1.1/src/cron_parser/__init__.py +0 -0
- cronjoborganize-0.1.1/src/cron_parser/cron_parser.py +151 -0
- cronjoborganize-0.1.1/src/cronjoborganize.egg-info/PKG-INFO +35 -0
- cronjoborganize-0.1.1/src/cronjoborganize.egg-info/SOURCES.txt +10 -0
- cronjoborganize-0.1.1/src/cronjoborganize.egg-info/dependency_links.txt +1 -0
- cronjoborganize-0.1.1/src/cronjoborganize.egg-info/entry_points.txt +2 -0
- cronjoborganize-0.1.1/src/cronjoborganize.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Moudi Alameel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cronjoborganize
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A command-line utility to parse and categorize cron job expressions into structured CSV reports
|
|
5
|
+
Author: Moudi Alameel
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
|
|
11
|
+
# cronjoborganize
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+

|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
A Python command-line tool designed to seamlessly parse and structure cron job expressions into well-organized CSV reports.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
* **Parse Cron Expressions:** Accurately reads standard cron scheduling syntax.
|
|
22
|
+
* **CSV Reporting:** Exports your parsed cron jobs into a structured, readable CSV format for straightforward auditing and analysis.
|
|
23
|
+
* **CLI Interface:** Provides a lightweight and intuitive command-line interface.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
You can install `cronjoborganize` directly from PyPI using pip:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install cronjoborganize
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
Use the tool from the command line to parse your cron files and generate reports:
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# cronjoborganize
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
A Python command-line tool designed to seamlessly parse and structure cron job expressions into well-organized CSV reports.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
* **Parse Cron Expressions:** Accurately reads standard cron scheduling syntax.
|
|
12
|
+
* **CSV Reporting:** Exports your parsed cron jobs into a structured, readable CSV format for straightforward auditing and analysis.
|
|
13
|
+
* **CLI Interface:** Provides a lightweight and intuitive command-line interface.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
You can install `cronjoborganize` directly from PyPI using pip:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install cronjoborganize
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Use the tool from the command line to parse your cron files and generate reports:
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "cronjoborganize"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "A command-line utility to parse and categorize cron job expressions into structured CSV reports"
|
|
9
|
+
authors = [
|
|
10
|
+
{ name="Moudi Alameel" }
|
|
11
|
+
]
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
dependencies = [
|
|
15
|
+
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[project.scripts]
|
|
19
|
+
# This creates the terminal command 'cron-organize'
|
|
20
|
+
cron-organize = "cron_parser.cron_parser:main"
|
|
File without changes
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import csv
|
|
2
|
+
import argparse
|
|
3
|
+
import math
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
def get_categorical_frequency(cron_expr):
|
|
8
|
+
special = {
|
|
9
|
+
'@reboot': 'On Startup',
|
|
10
|
+
'@yearly': 'Yearly',
|
|
11
|
+
'@annually': 'Yearly',
|
|
12
|
+
'@monthly': 'Monthly',
|
|
13
|
+
'@weekly': 'Weekly',
|
|
14
|
+
'@daily': 'Daily',
|
|
15
|
+
'@midnight': 'Daily',
|
|
16
|
+
'@hourly': 'Hourly'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if cron_expr in special:
|
|
20
|
+
return special[cron_expr]
|
|
21
|
+
|
|
22
|
+
parts = cron_expr.split()
|
|
23
|
+
if len(parts) < 5:
|
|
24
|
+
return "Unknown"
|
|
25
|
+
|
|
26
|
+
m, h, dom, mon, dow = parts[:5]
|
|
27
|
+
|
|
28
|
+
def get_step(val):
|
|
29
|
+
if val.startswith('*/'):
|
|
30
|
+
try: return int(val[2:])
|
|
31
|
+
except: pass
|
|
32
|
+
return None
|
|
33
|
+
|
|
34
|
+
if mon != '*':
|
|
35
|
+
step = get_step(mon)
|
|
36
|
+
if step == 3 or (',' in mon and len(mon.split(',')) == 4):
|
|
37
|
+
return 'Quarterly'
|
|
38
|
+
if step == 6 or (',' in mon and len(mon.split(',')) == 2):
|
|
39
|
+
return 'Biannually'
|
|
40
|
+
if ',' in mon:
|
|
41
|
+
return 'Multiple times a year'
|
|
42
|
+
return 'Yearly'
|
|
43
|
+
|
|
44
|
+
if dom != '*' or dow != '*':
|
|
45
|
+
dom_step = get_step(dom)
|
|
46
|
+
if dom_step:
|
|
47
|
+
if 5 <= dom_step <= 7: return 'Weekly'
|
|
48
|
+
if 13 <= dom_step <= 15: return 'Biweekly'
|
|
49
|
+
if dom_step >= 25: return 'Monthly'
|
|
50
|
+
return f'Every {dom_step} days'
|
|
51
|
+
|
|
52
|
+
if dow != '*' and '-' in dow:
|
|
53
|
+
return 'Daily'
|
|
54
|
+
|
|
55
|
+
if ',' in dom:
|
|
56
|
+
return 'Multiple times a month'
|
|
57
|
+
if ',' in dow:
|
|
58
|
+
return 'Multiple times a week'
|
|
59
|
+
|
|
60
|
+
if dom != '*' and dow == '*': return 'Monthly'
|
|
61
|
+
if dow != '*' and dom == '*': return 'Weekly'
|
|
62
|
+
return 'Weekly'
|
|
63
|
+
|
|
64
|
+
if h != '*':
|
|
65
|
+
h_step = get_step(h)
|
|
66
|
+
if h_step:
|
|
67
|
+
return f'Every {h_step} hours'
|
|
68
|
+
if '-' in h or ',' in h:
|
|
69
|
+
return 'Multiple times a day'
|
|
70
|
+
return 'Daily'
|
|
71
|
+
|
|
72
|
+
if m != '*':
|
|
73
|
+
m_step = get_step(m)
|
|
74
|
+
if m_step:
|
|
75
|
+
rounded_m = math.ceil(m_step / 5.0) * 5
|
|
76
|
+
if rounded_m >= 60: return 'Hourly'
|
|
77
|
+
if rounded_m == 30: return 'Half-hourly'
|
|
78
|
+
return f'Every {rounded_m} minutes'
|
|
79
|
+
if '-' in m or ',' in m:
|
|
80
|
+
return 'Multiple times an hour'
|
|
81
|
+
return 'Hourly'
|
|
82
|
+
|
|
83
|
+
return 'Every minute'
|
|
84
|
+
|
|
85
|
+
def process_cron_stream(input_stream, output_file):
|
|
86
|
+
lines = input_stream.readlines()
|
|
87
|
+
|
|
88
|
+
data = []
|
|
89
|
+
|
|
90
|
+
for line in lines:
|
|
91
|
+
line = line.strip()
|
|
92
|
+
if not line:
|
|
93
|
+
continue
|
|
94
|
+
|
|
95
|
+
is_commented = line.startswith('#')
|
|
96
|
+
cleaned_line = line.lstrip('#').strip() if is_commented else line
|
|
97
|
+
|
|
98
|
+
parts = cleaned_line.split()
|
|
99
|
+
if not parts:
|
|
100
|
+
continue
|
|
101
|
+
|
|
102
|
+
cron_expr = ""
|
|
103
|
+
raw_command = ""
|
|
104
|
+
|
|
105
|
+
if parts[0].startswith('@'):
|
|
106
|
+
cron_expr = parts[0]
|
|
107
|
+
raw_command = " ".join(parts[1:])
|
|
108
|
+
elif len(parts) >= 5 and any(char.isdigit() or char == '*' for char in parts[0]):
|
|
109
|
+
cron_expr = " ".join(parts[:5])
|
|
110
|
+
raw_command = " ".join(parts[5:])
|
|
111
|
+
else:
|
|
112
|
+
continue
|
|
113
|
+
|
|
114
|
+
frequency = get_categorical_frequency(cron_expr)
|
|
115
|
+
|
|
116
|
+
# Strip the directory path from the executable
|
|
117
|
+
executable = ""
|
|
118
|
+
if raw_command:
|
|
119
|
+
executable_path = raw_command.split()[0]
|
|
120
|
+
executable = os.path.basename(executable_path)
|
|
121
|
+
|
|
122
|
+
data.append({
|
|
123
|
+
'Executable': executable,
|
|
124
|
+
'Command/Task': raw_command,
|
|
125
|
+
'Frequency Bucket': frequency,
|
|
126
|
+
'Commented Out': 'Yes' if is_commented else 'No',
|
|
127
|
+
'Raw Cron Expression': cron_expr
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
with open(output_file, 'w', newline='') as csvfile:
|
|
131
|
+
fieldnames = ['Executable', 'Command/Task', 'Frequency Bucket', 'Commented Out', 'Raw Cron Expression']
|
|
132
|
+
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
|
|
133
|
+
writer.writeheader()
|
|
134
|
+
writer.writerows(data)
|
|
135
|
+
|
|
136
|
+
print(f"Successfully processed {len(data)} cron jobs. Output saved to {output_file}.")
|
|
137
|
+
|
|
138
|
+
def main():
|
|
139
|
+
parser = argparse.ArgumentParser(description="Parse and categorize cron job expressions into structured CSV reports")
|
|
140
|
+
parser.add_argument("input_file", nargs='?', type=argparse.FileType('r'), default=sys.stdin, help="The text file containing cron jobs")
|
|
141
|
+
parser.add_argument("-o", "--output", default="cron_analysis.csv", help="The output CSV file name")
|
|
142
|
+
|
|
143
|
+
args = parser.parse_args()
|
|
144
|
+
|
|
145
|
+
if args.input_file == sys.stdin and sys.stdin.isatty():
|
|
146
|
+
parser.error("You must provide an input file or pipe data to the command (e.g., crontab -l | cron-organize)")
|
|
147
|
+
|
|
148
|
+
process_cron_stream(args.input_file, args.output)
|
|
149
|
+
|
|
150
|
+
if __name__ == "__main__":
|
|
151
|
+
main()
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cronjoborganize
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A command-line utility to parse and categorize cron job expressions into structured CSV reports
|
|
5
|
+
Author: Moudi Alameel
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
|
|
11
|
+
# cronjoborganize
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+

|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
A Python command-line tool designed to seamlessly parse and structure cron job expressions into well-organized CSV reports.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
* **Parse Cron Expressions:** Accurately reads standard cron scheduling syntax.
|
|
22
|
+
* **CSV Reporting:** Exports your parsed cron jobs into a structured, readable CSV format for straightforward auditing and analysis.
|
|
23
|
+
* **CLI Interface:** Provides a lightweight and intuitive command-line interface.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
You can install `cronjoborganize` directly from PyPI using pip:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install cronjoborganize
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
Use the tool from the command line to parse your cron files and generate reports:
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/cron_parser/__init__.py
|
|
5
|
+
src/cron_parser/cron_parser.py
|
|
6
|
+
src/cronjoborganize.egg-info/PKG-INFO
|
|
7
|
+
src/cronjoborganize.egg-info/SOURCES.txt
|
|
8
|
+
src/cronjoborganize.egg-info/dependency_links.txt
|
|
9
|
+
src/cronjoborganize.egg-info/entry_points.txt
|
|
10
|
+
src/cronjoborganize.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cron_parser
|