Simple Node.js script to check the Raspberry Pi's CPU temperature and send an email alert if above set thresholds. The script and instructions provided are for using Gmail with OAuth2. I found no other way to send emails with Gmail, but using this script and provided instructions to set up OAuth2 works.
Inspired by Leonardo Gentile's Python script for the same thing.
Follow these excellent instructions to set up OAuth2 on your Gmail account to be able to send emails using nodemailer.
Prerequisites:
-
Node.js:
sudo apt install nodejs
-
NPM dependencies: nodemailer, googleapis, dotenv
run
npm i
in the script folder -
Rename .
env.example
to.env
and update it using client ID, client secret and refresh token obtained using above instructions -
Change the path in the Bash script
tempmon.sh
to match your absolute app path. Leave the Node path as is unless your distro keeps Node somewhere else. This is the path on Ubuntu ARM64 -
Add the job to crontab using
crontab -e
and adding the line*/30 * * * * /home/ubuntu/_projects/rasp-temp-alert/tempmon.sh
or whatever your path is, to run script every 30 minutes. Don't forget to add a blank line in crontab at the end