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

  1. Open a new script file using nano or your favorite text editor:

    sudo nano /usr/local/bin/sensors
    
  2. Add 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"
    
  3. 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:

  1. Simply log in to your Orange Pi with SSH and execute the script:

    ssh your_username@your_orangepi_ip "sensors"
    
  2. For a more concise command, you can add an alias on your local system:

    • Open your .bashrc or .zshrc file:
      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
      

Optional: Automate Monitoring

If you’d like regular monitoring:

  1. 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
      
  2. Monitor logs remotely:

    • Check the logs via SSH:
      ssh your_username@your_orangepi_ip "tail -f ~/temperature.log"
      

Let me know if you’d like help extending this script or automating it further! 😊