From 1ebb3dd4012305633ae68d1ac67a0f8b248afd0b Mon Sep 17 00:00:00 2001 From: silentvick Date: Tue, 25 Mar 2025 13:38:34 +0000 Subject: [PATCH 1/2] Fix shell argument escaping when setting remote crontab (#4036) --- contrib/crontab.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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); From e25e23b5064f6ee652064940b7a8906d7eb75b79 Mon Sep 17 00:00:00 2001 From: silentvick Date: Tue, 25 Mar 2025 13:54:31 +0000 Subject: [PATCH 2/2] Update crontab docs (#4036) --- docs/contrib/crontab.md | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) 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.