diff --git a/contrib/crontab.php b/contrib/crontab.php index 93bc8972e..8a8ae7c34 100644 --- a/contrib/crontab.php +++ b/contrib/crontab.php @@ -24,6 +24,8 @@ namespace Deployer; +use function Deployer\Support\escape_shell_argument; + // Get path to bin set('bin/crontab', function () { return which('crontab'); @@ -135,7 +137,7 @@ function setRemoteCrontab(array $lines): void } foreach ($lines as $line) { - run("echo '" . $line . "' >> $tmpCrontabPath"); + run("echo " . escape_shell_argument($line) . " >> $tmpCrontabPath"); } run("$sudo {{bin/crontab}} " . $tmpCrontabPath); diff --git a/docs/contrib/crontab.md b/docs/contrib/crontab.md index 596acaf66..375b9f5e1 100644 --- a/docs/contrib/crontab.md +++ b/docs/contrib/crontab.md @@ -29,21 +29,8 @@ add('crontab:jobs', [ ## Configuration ### bin/crontab -[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L28) +[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L30) -Recipe for adding crontab jobs. -This recipe creates a new section in the crontab file with the configured jobs. -The section is identified by the *crontab:identifier* variable, by default the application name. -## Configuration -- *crontab:jobs* - An array of strings with crontab lines. -## Usage -```php -require 'contrib/crontab.php'; -after('deploy:success', 'crontab:sync'); -add('crontab:jobs', [ - '* * * * * cd {{current_path}} && {{bin/php}} artisan schedule:run >> /dev/null 2>&1', -]); -``` Get path to bin ```php title="Default value" @@ -52,7 +39,7 @@ return which('crontab'); ### crontab:identifier -[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L33) +[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L35) Set the identifier used in the crontab, application name by default @@ -62,7 +49,7 @@ return get('application', 'application'); ### crontab:use_sudo -[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L38) +[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L40) Use sudo to run crontab. When running crontab with sudo, you can use the `-u` parameter to change a crontab for a different user. @@ -75,7 +62,7 @@ false ## Tasks ### crontab\:sync {#crontab-sync} -[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L41) +[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L43) Sync crontab jobs. @@ -83,7 +70,7 @@ Sync crontab jobs. ### crontab\:remove {#crontab-remove} -[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L85) +[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L87) Remove crontab jobs.