-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
35 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,14 +42,36 @@ Their order for execution is alphabetic (by using the sort command). Suggestion | |
Your hooks maybe want to access a few information to send a notification or whatever. | ||
These data may help you to generate a message. | ||
|
||
| variable | type | description | | ||
|--- |--- |--- | | ||
| `${CALLSCRIPT}` | {string} | executed command line | | ||
| `${FINALOUTFILE}` | {string} | filename of the final logfile of the job to send as information| | ||
| `${LABELSTR}` | {string} | label of the job| | ||
| `${MYHOST}` | {string} | hostname| | ||
| `${TTL}` | {int} | ttl value in minutes| | ||
| `${iStart}` | {int} | Unix timestamp of the starting time| | ||
| `${iEnd}` | {int} | Unix timestamp of the ending time (for after/*/*)| | ||
| `${iExectime}` | {int} | execution time in seconds (for after/*/*)| | ||
| `${rc}` | {int} | resturncode of the failed job (for after/on-error/*)| | ||
| variable | type | description | | ||
|--- |--- |--- | | ||
| CALLSCRIPT | {string} | executed command line | | ||
| FINALOUTFILE | {string} | filename of the final logfile of the job to send as information | | ||
| LABELSTR | {string} | label of the job| | ||
| OUTFILE | {string} | filename of the still running cronjob (for after/*/*); you can grep its content eg. "^SCRIPTOUT=" (see Output) | | ||
| MYHOST | {string} | hostname| | ||
| TTL | {int} | ttl value in minutes| | ||
| iStart | {int} | Unix timestamp of the starting time| | ||
| iEnd | {int} | Unix timestamp of the ending time (for after/*/*)| | ||
| iExectime | {int} | execution time in seconds (for after/*/*)| | ||
| rc | {int} | resturncode of the failed job (for after/on-error/*)| | ||
|
||
## Example | ||
|
||
### Send an email if a job failed | ||
|
||
Remark: | ||
To send an email you need to install a mailer like sendmail or postfix locally and configure it to be able to send trusted emails via your smtp gateway. | ||
|
||
Create a script as root eg. `hooks/after/on-error/send_email.sh`. | ||
Make it executable `chmod 0755 hooks/after/on-error/send_email.sh` | ||
|
||
Content of *send_email.sh*: | ||
|
||
```shell | ||
#!/bin/bash | ||
|
||
[email protected] | ||
SUBJECT="Cronjob on ${MYHOST} - ${LABELSTR} failed with rc=${rc}" | ||
|
||
cat "${OUTFILE}" | mail -s "${SUBJECT}" ${TO} | ||
``` |