Hello All, @huidbui25 , @Joulinar
Hope everyone is in good health and doing well.
This is great tutorial / script and I have been using this on DietPi running on few RPis. I had two old PC Engines APU 1d boxes lying around with 16GB mSATA and 2GB RAM and dual Atom CPU. It also has 3 Gig ethernet ports, one for WAN and 2 for LAN. I first did BIOS upgrade to latest available. Then used DietPi script for Other hardware on it (after installing Debian 11) and successfully converted to DietPi latest version. Could not make the built-in serial / DB9 port working though.
I was able to see my interfaces and did some quick tests. All looked okay. But then found that every few minutes the box will shutdown. Could not find any clues as to why.
Spent many hours and then reverted back to Debian 11. All those issues went away and I also got control of serial port.
Installed UFW and IP tables persistent and I am able to use NAT also from two LAN ports to go to internet via WAN port. Then installed NoMachine with LXDE and that also works great. Of course Firefox gives some grief in terms of how much CPU hog it is. But that is not a concern, as I will hardly use browser on this box.
I then installed OpenVPN for client and successfully made it auto connect on reboot to the AWS / Ubuntu based PiVPN server.
Then I looked for vcgencmd and found that this package is only available on Raspbian OS. I really wanted to use the script written by @huidbui25. But I then installed sensors package and though to slightly modify the script and achieve the results. The output of sensors is in a different format and it shows temperature twice (for two cores).
I replaced, the part,
tmp_akt=$(vcgencmd measure_temp | cut -f 2 -d “=” | cut -f 1 -d “'” | grep -E ‘^-?[0-9]*.?[0-9]+$’)
with
tmp_chk=$(awk ‘/temp1/ {print +$2}’ <(sensors) | head -1 | cut -b 1,2)
If I try to use the grep part from original script, it complains. Essentially what I find is the the output from my script is essentially a string and not an integer that I need.
Further below, under the statements to check for warning and alarm conditions, if I use bc -l, then it complains of syntax error, obviously, if result of tmp_akt was string and if I remove bc (anyway, I was not using decimals after temp and had cut it to two digit number only), and then this error goes away. But then further down below, the if condition was expecting results to be 0 or 1, which it outputs as string like ‘57 -gt 67’ and ‘57 -gt 77’
So I am looking for some help. In the past, I have twice donated to the project. If I can be helped with this script working on PC Engines box running Debian, I will donate another $100 (USD though I am in Canada) to the project.
Ultimately, I will try to get back to DietPi on these two boxes as well.
Running bash -x on the script shows the issue:
root@TestHost:~# bash -x /usr/local/bin/temp_mon
- tmp_warn=67
- tmp_alarm=77
- tmp_unit=C
- FROM_NAME=‘PCEng Lab’
- FROM_ADDRESS=PCEng@domain.com
- TO_NAME=‘PC Engines’
- TO_ADDRESS=Lab@domain.com
- MAIL_FILE=/tmp/mail_tmp.txt
++ bc -l
++ cut -b 1,2
++ head -1
++ awk ‘/temp1/ {print +$2}’ /dev/fd/63
+++ sensors - tmp_akt=57
- ‘[’ ‘’ == test ‘]’
- ‘[’ -z 57 ‘]’
++ echo 57 -gt 67 - status_warn=‘57 -gt 67’
++ echo 57 -gt 77 - status_alarm=‘57 -gt 77’
- [[ ‘’ == 0 ]]
- echo ‘From: “PCEng Lab” PCEng@domain.com’
- echo ‘To: “Lab” Lab@domain.com’
- ‘[’ == 1 ‘]’
/usr/local/bin/temp_mon: line 47: [: ==: unary operator expected - ‘[’ == 1 ‘]’
/usr/local/bin/temp_mon: line 53: [: ==: unary operator expected - echo ‘Content-type: text/plain; charset=utf-8’
- echo ‘Content-Language: en’
- echo ‘X-Auto-Response-Suppress: OOF’
- echo ‘’
- echo ‘CPU temperature is melting hot!’
- echo ‘Current temp: 57 °C’
- ‘[’ ‘’ == test ‘]’
- echo ‘’
- echo '— ’
- echo ‘Sent by temp_mon script’
- echo ‘’
- cat /tmp/mail_tmp.txt
- sendmail -f PCEng@domain.com Lab@domain.com
- logger ‘temp_mon: high CPU temperature: 57 °C, mail sent’
- rm /tmp/mail_tmp.txt
Thanks so much.