0

I got a script from link: https://forum.openmediavault.org/index.php?thread/6902-fan-control/. which I plan to use to control fan speed according to harddisk temperature and CPU temperature.

After I finished check actual sensor and controller by pwmconfig, modify it with actual sensor and controller.

change the script privilege to executable script. run it with root privilege.

run it in terminal then it report error.

fan_controllers.sh: line 19: used: command not found

the detail of the script like below, something I marked with annotation, purpose to trial run the script.

#!/bin/bash
HDDS="/dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde"
HDT=hddtemp
LOG=
DOWN=
ALERT_LEVEL=50
args="--numeric"
VALUE_SIDE=0
VALUE_BACK=0
#while true
#do
        #sleep 1
        CPU=0
        VALUE_SIDE=0
        VALUE_BACK=0
        I=0
        for disk in $HDDS
        do
                HDTEMP=$(hdparm -C $disk)# This is line 19. used to inspect the harddisk status,whether it is in status of standby or some others
                if [[ $HDTEMP != *standby* ]]; then
                        VALUE_SIDE=$(($VALUE_SIDE + 255))
                        VALUE_BACK=150
                        I=$(($I + 1))
                fi
        done
        CPU1=$(cat /sys/class/hwmon/hwmon0/temp1_input) #hwmon0 is CPU temperaturer sensor
        CPU2=$(cat /sys/class/hwmon/hwmon0/temp2_input)
        #CPU3=$(cat /sys/class/hwmon/hwmon1/device/temp4_input)
        #CPU4=$(cat /sys/class/hwmon/hwmon1/device/temp5_input)
        #CPU=$(($CPU1 + $CPU2 + $CPU3 + $CPU4))
        #CPU=$(($CPU / 4000))
        CPU=$(($CPU1 + $CPU2))
        CPU=$(($CPU / 2000))        
        if [ $CPU -ge 40 2>&- ]; then
                VALUE_BACK=105
        fi
        if [ $CPU -ge 45 2>&- ]; then
                VALUE_BACK=150
        fi
        if [ $HDTEMP -ge 55 2>&- ]; then
                VALUE_BACK=255
        fi
        if [ $I -ge 1 2>&- ]; then
                VALUE_SIDE=$(($VALUE_SIDE / $I))
        fi
        echo $VALUE_SIDE
        echo $VALUE_BACK
        #echo 1 > /sys/class/hwmon/hwmon3/pwm1_enable #pwm1 is chase fan it will be decided by actual boards
        #echo 1 > /sys/class/hwmon/hwmon3/pwm2_enable #CPU fan
        #echo $VALUE_SIDE > /sys/class/hwmon/hwmon3/pwm1
        #echo $VALUE_BACK > /sys/class/hwmon/hwmon3/pwm2
#done

the OS is Openmedialvault6, based on debian.

I suspect the problem caused by the command "hdparm", but when I try it separately in terminal, it works, no issue report.


hdparm -C /dev/sda

/dev/sda:
 drive state is:  active/idle

I run it with root privilege.

I don't know what happened, would someone could give me some advice about it?

Thanks!

Hope could find the reason why reports

fan_controllers.sh: line 19: used: command not found

and solve it.

beni
  • 1
  • please update the question to show the *exact* contents of your shell script's line 19 (don't add/modify any comments); I'm assuming line 19 actually looks something like `HDTEMP=$(hdparm -C $disk)# used ...` in which case `HDTEMP` is assigned the output from `heparm` command *plus* the character `#` and then `bash` things `used` is a new/separate command and since `used` is not a valid command you get the error – markp-fuso Jul 08 '23 at 14:11
  • 1
    I can simulate the same error with this command: `x=$(date)# used` ==> `-bash: used: command not found`; in this case the solution is to add (at least) one space in front of the `#` (ie, `x=$(date) # used`) ; without the separating whitespace `bash` treats the `#` as part of the assignment instead of the start of a comment; provide whitespace before the `#` so that `bash` treats `#` as the start of a comment – markp-fuso Jul 08 '23 at 14:13
  • 1
    Note that part of your job when writing a question is to build a [MRE]. It's not "minimal" to include the whole script if you can test that the one line that the problem is reported on is enough to create the error on its own. – Charles Duffy Jul 08 '23 at 14:18
  • @markp-fuso, thank you very much for you to indicate the error I missed! I should put a space in front of the `#`, I correct it and the script work well. I'm not familiar with bash script, so that made me to make the mistake. thank you for your help about that. – beni Jul 09 '23 at 00:26
  • @CharlesDuffy, thanks for your advice, I hope the total script will make people to understand the question, considered it is only a short script, so I past it all to here. as a newbie, sometimes it is hard to found what the actual problems is. – beni Jul 09 '23 at 00:29
  • Would someone help me explain what the meaning of the command `if [ $I -ge 1 2>&- ]; then`, I tried to find explanation about the `2>&-` from internet, but didn't find the answer of it. – beni Jul 09 '23 at 00:31
  • @beni, `2>&-` closes stderr. It's bad practice, because closing standard file descriptors can cause new errors in programs that otherwise wouldn't fail; using `2>/dev/null` is much better form. – Charles Duffy Jul 09 '23 at 01:27

0 Answers0