TiBeN / CrontabManager

PHP library for GNU/Linux cron jobs management.
Other
137 stars 29 forks source link

Problem in createFromCrontabLine when # used in the command #19

Open rreich69 opened 5 months ago

rreich69 commented 5 months ago

I ran into an issue where the full command is something like this:

0 0 * cd /Users/../commands/; php somescript.php -p 'password#' >> /logs/somescript.log #some comment

In this case the '#' character that is part of the quoted password after the -p (part of a password) fails the preg_match in the createFromCrontabLine function in the CrontabJob class. If I remove the '#' character from the password it works just fine.

It saved to the crontab using this package just fine and appears in the crontab when looking at it on command line on the server, but it fails when trying to read it back out. I'd suggest a fix, but that regex is a little over my head.

TiBeN commented 5 months ago

This one was quite challenging! Thank you for report this.

I think i fixed the issue by reworking the regex. All tests are passing, including your crontab line, but now the regex becomes more complex and i would like to take time for more tests to prevent regressions before pushing it to master.

As a quick fix you can use this branch: https://github.com/TiBeN/CrontabManager/tree/regex-hash-fix

EDIT: as a workaround you can put as well your command in a simple bash script file.