node-cronlog is lightweight node-js script that helps to log cron jobs (or other scripts) and send an email if something went wrong (using nodemailer + Gmail).
OPTIONAL: If you want to receive alerts via email if something went wrong
Create a file named ~/.cronlog/.env
GMAIL_USER="[email protected]"
GMAIL_PWD="**********"
MAIL_TO="[email protected]"
IMPORTANT NOTE: If you have enabled 2FA on your GMAIL account, you need to create an "App-specific password" from your gmail account settings.
First, run npm install
to install the dependencies.
Then, call the script.
# Launch the script
/path/to/cronlog.js <jobname> /path/to/command [options...]
To use the script from CRON, install the package globally npm install -g /path/to/node-cronlog
* * * * * cronlog my_job_name echo "MY SCRIPT WORKS WELL"
The last result of each job will be stored in a SQLite file at ~/.cronlog/cronlog.sqlite
name | cmd | started | completed | duration | output | status |
---|---|---|---|---|---|---|
my_job_name | echo MY SCRIPT WORKS WELL | 2020-09-19T15:48:26.313Z | 2020-09-19T15:48:26.319Z | 0.006 | MY SCRIPT WORKS WELL | 0 |