I am pretty new to bash scripting, but I upon setting up a NAS with FreeNAS I found that the GUI has no default implementation for logging HDD temperatures, so I tried to set up a bash script that would log temps to a file and run as a cron job. What I ended up piecing together looks very messy, but works when run as a script from the console.
HDDtemps.sh:
#!/bin/bash --
PATH=$PATH:/tmp:/usr/local/sbin
printf '%s %s %s %s %s\n' $(echo -n $(date +"%b %d %T")) ' :: ada0 Temperature Celsius = ' $(echo $(smartctl -A /dev/ada0 | grep Temperature_Celsius) | awk '{print $10}') >> temperatures.txt
printf '%s %s %s %s %s\n' $(echo -n $(date +"%b %d %T")) ' :: ada1 Temperature Celsius = ' $(echo $(smartctl -A /dev/ada1 | grep Temperature_Celsius) | awk '{print $10}') >> temperatures.txt
exit;
When executed by cron however, the file is created and is printed into, but only
Feb 17 19:22:00 :: ada0 Temperature Celsius =
is written to the file, the temperature is does not appear. I am not sure what I am doing wrong here, and I would appreciate any help.
Thanks!
EDIT:
The cronjob is
* * * * * sh /path/to/HDDtemps.sh
也许,验证smartctl二进制文件是否存在于/ usr / sbin /中,并在cronjob运行的脚本中为smartctl指定绝对路径/ usr / sbin / smartctl ,因此将smartctl替换为/ usr / sbin / smartctl 。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.