diff --git a/chkcrontab_lib.py b/chkcrontab_lib.py
index 12778cdb7f6b8f452034c4648df8a6c77ee38b3b..54cc70397f7487697fe613796ded161af9d52419 100755
--- a/chkcrontab_lib.py
+++ b/chkcrontab_lib.py
@@ -681,6 +681,11 @@ class CronLineAssignment(object):
'Variable assignments in crontabs are not like shell.'
' $VAR is not expanded.')
+ if re.match('".+" ?#', self.variable) or re.match('[^"].*#', self.variable):
+ log.LineError(log.MSG_COMMENT,
+ 'Variable assignments in crontabs are not like shell.'
+ ' # comment is not allowed.')
+
class CronLineTimeAction(object):
"""Checks cron lines that specify a time and an action.
@@ -881,7 +886,8 @@ class LogCounter(object):
'QUOTE_VALUES',
'SHELL_VAR',
'USER_NOT_FOUND',
- 'HOURS_NOT_MINUTES'))
+ 'HOURS_NOT_MINUTES',
+ 'COMMENT'))
def __init__(self):
"""Inits LogCounter."""
diff --git a/tests/test_crontab.disable b/tests/test_crontab.disable
index 6fac9b1c256ac6808d8e112d8fa6bd485c93648e..9808b331b69ed4312dad82d88be30cdf20873b7d 100644
--- a/tests/test_crontab.disable
+++ b/tests/test_crontab.disable
@@ -24,6 +24,11 @@ OK_EMPTY=""
BAD_SPACE=
OK_SPACE=" "
+# disable fail 1 for comment in variable assignment.
+NO_COMMENT="something" # comment
+NO_COMMENT=something # comment
+NO_COMMENT="something # comment"
+
# disable warn 1 for bad time spec.
* 3 * * * root Warn for hours not minutes
# disable fail 1 for bad time spec.
@@ -74,7 +79,7 @@ OK_SPACE=" "
1,4,6,*/5 */3,2,7 * * mOn-Fri root Good Day Range
1,4,6,*/5 */3,2,7 * * mOn-Fri/2 root Good Day Range Step
# chkcrontab: enable-msg=FIELD_VALUE_ERROR
-# FAIL 1 for bad time spec.
+# FAIL 3 for bad time spec.
1,4,6,*/5 */3,2,7 * * mOn/2 root Bad Day Step
1,4,6,*/5 */3,2,7 * * mOn-Fri/8 root Good Day Range Step
# disable warn 1 for probable missing user.