Skip to content

Commit a87081f

Browse files
authored
Fix #4036: Escape shell argument when setting remote crontab (#4042)
* Fix shell argument escaping when setting remote crontab (#4036) * Update crontab docs (#4036)
1 parent ff07090 commit a87081f

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

contrib/crontab.php

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

2525
namespace Deployer;
2626

27+
use function Deployer\Support\escape_shell_argument;
28+
2729
// Get path to bin
2830
set('bin/crontab', function () {
2931
return which('crontab');
@@ -135,7 +137,7 @@ function setRemoteCrontab(array $lines): void
135137
}
136138

137139
foreach ($lines as $line) {
138-
run("echo '" . $line . "' >> $tmpCrontabPath");
140+
run("echo " . escape_shell_argument($line) . " >> $tmpCrontabPath");
139141
}
140142

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

docs/contrib/crontab.md

Lines changed: 5 additions & 18 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#L30)
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#L35)
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#L40)
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,15 +62,15 @@ false
7562
## Tasks
7663

7764
### crontab\:sync {#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#L43)
7966

8067
Sync crontab jobs.
8168

8269

8370

8471

8572
### crontab\:remove {#crontab-remove}
86-
[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L85)
73+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/crontab.php#L87)
8774

8875
Remove crontab jobs.
8976

0 commit comments

Comments
 (0)