librenms / librenms-agent

LibreNMS Agent & Scripts
GNU General Public License v2.0
116 stars 187 forks source link

Fixing agent-local hddtemp script #436

Closed bnerickson closed 1 year ago

bnerickson commented 1 year ago

With quotes surrounding ${disks}, the hddtemp command attempts to execute across the entire string. If, for instance, the string contains multiple drives like "/dev/sda /dev/sdb", then this entire string is what hddtemp operates over. Without quotes, however, hddtemp parses each space-delimited drive individually:

With quotes (bad):

[abc@xyz ~]$ echo $disks
/dev/sda /dev/sda1
[abc@xyz ~]$ echo $hddtemp
/usr/bin/hddtemp
[abc@xyz ~]$ ${hddtemp} -w -q "${disks}"
/dev/sda /dev/sda1: open: No such file or directory
[abc@xyz ~]$ sudo /usr/lib/check_mk_agent/local/hddtemp
<<<hddtemp>>>
||||

[abc@xyz ~]$ 

Without quotes (good):

[abc@xyz ~]$ echo $disks
/dev/sda /dev/sda1
[abc@xyz ~]$ echo $hddtemp
/usr/bin/hddtemp
[abc@xyz ~]$ ${hddtemp} -w -q ${disks}
/dev/sda: Samsung SSD 850 EVO 250GB: 34°C
/dev/sda1: Samsung SSD 850 EVO 250GB: 34°C
[abc@xyz ~]$ sudo /usr/lib/check_mk_agent/local/hddtemp
<<<hddtemp>>>
|/dev/sda|Samsung SSD 850 EVO 250GB|34|C||/dev/sda1|Samsung SSD 850 EVO 250GB|34|C|

[abc@xyz ~]$