diff --git a/docs/30_Usage/20_Output.md b/docs/30_Usage/20_Output.md index 84bd619..ca17832 100644 --- a/docs/30_Usage/20_Output.md +++ b/docs/30_Usage/20_Output.md @@ -76,14 +76,14 @@ To detect outdated jobs see section for cronstatus.sh on the next page. | value | type | description | |--- |--- |--- | -| SCRIPTNAME | string | commandline of executed job; The value is taken from 1st parameter of cronwrapper commandline | +| SCRIPTNAME | string | commandline of executed job; The value is taken from 1st parameter of cronwrapper commandline | | SCRIPTTTL | integer | TTL value: in how many minutes this cronjob wust be repeated? The value is taken from 2nd parameter of cronwrapper commandline | | SCRIPTSTARTTIME | datetime | starting time of the cronjob as time and (after comma) as unix timestamp; eg. `2022-09-22 09:48:58, 1663832938`| | SCRIPTLABEL | string | label that will be part of the flag file and the log file name in the output directory. By default it is generated but you can override it with a 3rd parameter in cronwrapper commandline | | SCRIPTPROCESS | integer | process id | | JOBEXPIRE | integer | Unix timestamp when the job is expired. t is calculated by starttime plus TTL | | SCRIPTENDTIME | datetime | ending time of the cronjob as time and (after comma) as unix timestamp; eg. `2022-09-22 09:48:12, 1663832938`| -| SCRIPTEXECTIME | string | Needed time for execution in seconds as human readable time; the delta of endtime - starttime | +| SCRIPTEXECTIME | string | Needed time for execution in seconds as human readable time; the delta of endtime - starttime; the time for execution of hooks is excluded | | SCRIPTRC | integer | returncode of the executed commandline | | SCRIPTOUT | string | Output of the executed command. This value can be repeated in the log on multiline outputs diff --git a/docs/30_Usage/50_Hooks.md b/docs/30_Usage/50_Hooks.md index 17a4be7..01cdbc9 100644 --- a/docs/30_Usage/50_Hooks.md +++ b/docs/30_Usage/50_Hooks.md @@ -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 + +TO=sysadmin@example.com +SUBJECT="Cronjob on ${MYHOST} - ${LABELSTR} failed with rc=${rc}" + +cat "${OUTFILE}" | mail -s "${SUBJECT}" ${TO} +```