-
-
Save ahmedsbytes/bc890084b0a6266ab105b6e5fd898475 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import os | |
fd = open('/etc/crontab') | |
ignored_lines = 0 | |
shell = path = mailto = '' | |
crons = list() | |
shell_pattern = re.compile('SHELL=["\']?((/[a-zA-Z]+)+)["\']?') | |
path_pattern = re.compile('PATH=["\']?(((/[a-zA-Z]+)+:?)+)["\']?') | |
mailto_pattern = re.compile('MAILTO=([a-zA-Z0-9\-_]+(@[a-zA-Z0-9\-_]+\.[a-zA-Z0-9\-_]+)?)') | |
command_match = re.compile('#?(((((([0-9]+,?)+)|\*|(\*/[0-9]+)))[ \t]+){5}([a-zA-Z0-9]+)[ \t]+(.+))') | |
comment_match = re.compile('#.+') | |
class CronItem: | |
pre_comment = cmd = moh = hod = dom = moy = dow = '' | |
commented = False | |
def __init__(self): | |
pass | |
line = 0 | |
for x in fd: | |
line += 1 | |
if len(x.strip()) > 0: | |
match = shell_pattern.match(x) | |
if match and len(match.groups()) > 0: | |
shell = match.groups()[0] | |
continue | |
match = path_pattern.match(x) | |
if match and len(match.groups()) > 0: | |
path = match.groups()[0] | |
continue | |
match = mailto_pattern.match(x) | |
if match and len(match.groups()) > 0: | |
mailto = match.groups()[0] | |
continue | |
match = command_match.match(x) | |
if match and len(match.groups()) > 0: | |
cmd = str(match.groups()[-1]) | |
print os.execl("/bin/bash", ' -n', cmd) | |
continue | |
match = comment_match.match(x) | |
if match and len(match.groups()) > 0: | |
match.groups() | |
continue | |
print(" line %s is not valid" % line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment