Skip to content

Commit

Permalink
Fixed english grammar typos and improve README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
TiBeN committed Nov 30, 2014
1 parent a3ba00c commit 91155ba
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

PHP library to manage programmatically GNU/Linux cron jobs.

It enable you to :
It enables you to :

- Deal with your cron jobs in PHP.
- Create new Cron jobs.
Expand All @@ -24,19 +24,19 @@ composer require tiben/crontab-manager ~1.0
## Usage:
The library is composed of three classes:

- `CrontabJob` is an entity class which represent a cron Job.
- `CrontabRepository` is used to persist/retrieve your jobs.
- `CrontabAdapter` abstract raw crontab read/write.
- `CrontabJob` is an entity class which represents a cron job.
- `CrontabRepository` is used to persist/retrieve your cron jobs.
- `CrontabAdapter` handles cron jobs persistance in the crontab.

### Instanciate the repository:
In order to work, the CrontabRepository need an instance of CrontabAdapter which handle raw read/write against the crontab.
In order to work, the CrontabRepository needs an instance of CrontabAdapter.

```php
$crontabRepository = new CrontabRepository(new CrontabAdapter());
```

### Create new Job and persist it into the crontab:
Suppose you want to create an new job which consist of launching the command "df >> /tmp/df.log" every day at 23:30. You can do it in two ways.
Suppose you want to create an new job which consists of launching the command "df >> /tmp/df.log" every day at 23:30. You can do it in two ways.

- In Pure oo way :
```php
Expand All @@ -50,7 +50,7 @@ $crontabJob->taskCommandLine = 'df >> /tmp/df.log';
$crontabJob->comments = 'Logging disk usage'; // Comments are persisted in the crontab
```

- From raw cron syntax string using a factory method :
- From raw cron syntax string using a factory method :
```php
$crontabJob = CrontabJob::createFromCrontabLine('30 23 * * * df >> /tmp/df.log');
```
Expand All @@ -62,7 +62,7 @@ $crontabRepository->persist();
```

### Find a specific cron job from the crontab repository and update it:
Suppose we want to modify the hour of an already existing cronjob. Finding existings jobs is made using some regular expressions. Search in made against the entire crontab line.
Suppose we want to modify the hour of an already existing cronjob. Finding existings jobs is done using some regular expressions. The regex is applied to the entire crontab line.
```php
$results = $crontabRepository->findJobByRegex('/Logging\ disk\ usage/');
$crontabJob = $results[0];
Expand All @@ -81,31 +81,31 @@ $crontabRepository->persist();
Note: Since cron jobs are internally matched by reference, they must be previously obtained from the repository or previously added.

### Work with the crontab of another user than runtime user:
This feature allow you to manage the crontab of another user than the user who launched the runtime. This can be useful when the runtime user is `www-data` but the owner of the crontab you want to edit is your own linux user account.
This feature allows you to manage the crontab of another user than the user who launched the runtime. This can be useful when the runtime user is `www-data` but the owner of the crontab you want to edit is your own linux user account.

To do this, simply pass the username of the crontab owner as parameter of the CrontabAdapter constructor. Suppose you are `www-data` and you want to edit the crontab of user `bobby`:
```php
$crontabAdapter = new CrontabAdapter('bobby');
$crontabRepository = new CrontabRepository($crontabAdapter);
```

Using this way you will propably run into user rights issue.
This can be resolved by editing your sudoers file using 'visudo'.
Using this way you will propably run into user rights issues.
This can be handled by editing your sudoers file using 'visudo'.
If you want to allow user `www-data` to edit the crontab of user `bobby`, add this line:
```
www-data ALL=(bobby) NOPASSWD: /usr/bin/crontab
```
which tell sudo to not ask for password when call `crontab` of user `bobby`
which tells sudo not to ask for password when user `www-data` calls `crontab` as user `bobby` using `sudo`

Now, you can access to the crontab of user `bobby` like this :
```php
$crontabAdapter = new CrontabAdapter('bobby', true);
$crontabRepository = new CrontabRepository($crontabAdapter);
```
Note the second parameter `true` of the CrontabAdapter constructor call. This boolean tell the CrontabAdapter to use 'sudo' internally to read/write the crontab.
Note the second parameter `true` of the CrontabAdapter constructor call. This boolean tells the CrontabAdapter to use `sudo` internally when calling `crontab`.

### Enable or disable a cron job
You can enable or disable your cron jobs by setting the "enabled" attribute of a CronJob object accordingly :
You can enable or disable your cron jobs by setting the `enabled` attribute of a CronJob object accordingly :
```php
$crontabJob->enabled = false;
```
Expand Down

0 comments on commit 91155ba

Please sign in to comment.