Creating a simple Bash script to check the temperature on your Armbian-based Orange Pi Zero and triggering it via SSH is a great idea! Here’s how you can set it up:
1. Create the Script
Open a new script file using
nanoor your favorite text editor:sudo nano /usr/local/bin/sensorsAdd the following code to read the temperature:
#!/bin/bash # Script to check the CPU temperature # Read the raw temperature value RAW_TEMP=$(cat /sys/class/thermal/thermal_zone0/temp) # Convert to Celsius TEMP_C=$((RAW_TEMP / 1000)) # Output the temperature echo "CPU Temperature: ${TEMP_C}°C"Save the file (
Ctrl+O,Enter,Ctrl+X).
2. Make the Script Executable
Make the script executable with the following command:
sudo chmod +x /usr/local/bin/sensors
3. Test the Script
Run the script to verify it works:
/usr/local/bin/sensors
You should see something like:
CPU Temperature: 78°C
4. Trigger the Script via SSH
To trigger this script via SSH:
Simply log in to your Orange Pi with SSH and execute the script:
ssh your_username@your_orangepi_ip "sensors"For a more concise command, you can add an alias on your local system:
- Open your
.bashrcor.zshrcfile:nano ~/.bashrc - Add an alias like this:
alias sensors="ssh your_username@your_orangepi_ip 'sensors'" - Reload your shell configuration:
source ~/.bashrc - Now, you can simply type:
sensors
- Open your
Optional: Automate Monitoring
If you’d like regular monitoring:
Log temperatures periodically:
- Add a cron job to append temperatures to a log file:
crontab -e - Add a line like this to log temperatures every 5 minutes:
*/5 * * * * sensors >> ~/temperature.log
- Add a cron job to append temperatures to a log file:
Monitor logs remotely:
- Check the logs via SSH:
ssh your_username@your_orangepi_ip "tail -f ~/temperature.log"
- Check the logs via SSH:
Let me know if you’d like help extending this script or automating it further! 😊