Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Kevin Lyda
chkcrontab
Commits
5b479547
Commit
5b479547
authored
Aug 10, 2016
by
Hanspeter Spalinger
Browse files
pass arguments as dict
parent
1379262c
Changes
2
Show whitespace changes
Inline
Side-by-side
chkcrontab
View file @
5b479547
...
...
@@ -42,7 +42,7 @@ def main(argv):
log
=
check
.
LogCounter
()
print
(
'Checking correctness of %s'
%
args
.
crontab
)
return
check
.
check_crontab
(
args
.
crontab
,
log
,
args
.
whitelisted_users
)
return
check
.
check_crontab
(
args
,
log
)
if
__name__
==
'__main__'
:
sys
.
exit
(
main
(
sys
.
argv
))
chkcrontab_lib.py
View file @
5b479547
...
...
@@ -1053,14 +1053,14 @@ class LogCounter(object):
return
self
.
_error_count
def
check_crontab
(
crontab_file
,
log
,
whitelisted_users
=
None
):
def
check_crontab
(
arguments
,
log
):
"""Check a crontab file.
Checks crontab_file for a variety of errors or potential errors. This only
works with the crontab format found in /etc/crontab and /etc/cron.d.
Args:
crontab_file: Name of
the crontab file
to check.
arguments: ArgumentPArser Object containing
the crontab file
and options
log: A LogCounter object.
whitelisted_users: A list of users to ignore when warning on unrecognized users.
...
...
@@ -1071,18 +1071,18 @@ def check_crontab(crontab_file, log, whitelisted_users=None):
"""
# Check if the file even exists.
if
not
os
.
path
.
exists
(
crontab
_file
):
if
not
os
.
path
.
exists
(
arguments
.
crontab
):
return
log
.
Summary
()
# Add the any specified users to the whitelist
if
whitelisted_users
:
USER_WHITELIST
.
update
(
whitelisted_users
)
if
arguments
.
whitelisted_users
:
USER_WHITELIST
.
update
(
arguments
.
whitelisted_users
)
# Check the file name.
if
re
.
search
(
'[^A-Za-z0-9_-]'
,
os
.
path
.
basename
(
crontab
_file
)):
if
re
.
search
(
'[^A-Za-z0-9_-]'
,
os
.
path
.
basename
(
arguments
.
crontab
)):
in_whitelist
=
False
for
pattern
in
FILE_RE_WHITELIST
:
if
pattern
.
search
(
os
.
path
.
basename
(
crontab
_file
)):
if
pattern
.
search
(
os
.
path
.
basename
(
arguments
.
crontab
)):
in_whitelist
=
True
break
if
not
in_whitelist
:
...
...
@@ -1091,7 +1091,7 @@ def check_crontab(crontab_file, log, whitelisted_users=None):
line_no
=
0
cron_line_factory
=
CronLineFactory
()
with
open
(
crontab
_file
,
'r'
)
as
crontab_f
:
with
open
(
arguments
.
crontab
,
'r'
)
as
crontab_f
:
for
line
in
crontab_f
:
missing_newline
=
line
[
-
1
]
!=
"
\n
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment