Skip to content

Commit 81f88fa

Browse files
authored
Fix #4036: Escape shell argument when setting remote crontab (#4046)
1 parent 2f49c9b commit 81f88fa

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

contrib/crontab.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
namespace Deployer;
2727

28+
use function Deployer\Support\escape_shell_argument;
29+
2830
// Get path to bin
2931
set('bin/crontab', function () {
3032
return which('crontab');
@@ -95,7 +97,7 @@ function setRemoteCrontab(array $lines): void
9597
}
9698

9799
foreach ($lines as $line) {
98-
run("echo '" . $line . "' >> $tmpCrontabPath");
100+
run("echo " . escape_shell_argument($line) . " >> $tmpCrontabPath");
99101
}
100102

101103
run("$sudo {{bin/crontab}} " . $tmpCrontabPath);

docs/contrib/crontab.md

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,8 @@ add('crontab:jobs', [
2929

3030
## Configuration
3131
### bin/crontab
32-
[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L28)
32+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L31)
3333

34-
Recipe for adding crontab jobs.
35-
This recipe creates a new section in the crontab file with the configured jobs.
36-
The section is identified by the *crontab:identifier* variable, by default the application name.
37-
## Configuration
38-
- *crontab:jobs* - An array of strings with crontab lines.
39-
## Usage
40-
```php
41-
require 'contrib/crontab.php';
42-
after('deploy:success', 'crontab:sync');
43-
add('crontab:jobs', [
44-
'* * * * * cd {{current_path}} && {{bin/php}} artisan schedule:run >> /dev/null 2>&1',
45-
]);
46-
```
4734
Get path to bin
4835

4936
```php title="Default value"
@@ -52,7 +39,7 @@ return which('crontab');
5239

5340

5441
### crontab:identifier
55-
[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L33)
42+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L36)
5643

5744
Set the identifier used in the crontab, application name by default
5845

@@ -62,7 +49,7 @@ return get('application', 'application');
6249

6350

6451
### crontab:use_sudo
65-
[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L38)
52+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L41)
6653

6754
Use sudo to run crontab. When running crontab with sudo, you can use the `-u` parameter to change a crontab for a different user.
6855

@@ -75,7 +62,7 @@ false
7562
## Tasks
7663

7764
### crontab:sync
78-
[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L41)
65+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L44)
7966

8067
Sync crontab jobs.
8168

0 commit comments

Comments
 (0)