與我最後一個問題的所有類型的答覆我已經能夠創建一個小腳本來檢查我的NAS上的溫度,但現在我努力發送到後臺。當我嘗試啓動我的腳本發送bash腳本到背景開始
sh temp_check.sh start
我得到指着這條線
$0 background &
錯誤,我想不通爲什麼:/ 這是我的整個腳本
#!/ffp/bin/sh
#
#check CPU and HDD temperature and shutdown if too hot
#Settings
cpu_high=60
hdd_high=50
NAME="temp_check"
PIDFILE="/var/run/$NAME.pid"
Background() {
echo $$ >$PIDFILE
exec >/dev/null 2>&1
trap "rm -f $PIDFILE ; exit 0" INT TERM EXIT
while true; do
STATE=$(hdparm -C /dev/sda1 | grep "drive state" | awk '{print $4}')
if [ "$STATE" = "active/idle" ]; then
hdd_temp=$(/usr/local/zy-pkgs/bin/smartctl -A -d marvell /dev/sda | grep 194 | cut -d: -f3 | awk '{print $10}')
cpu_temp=$(i2cget -y 0x0 0x0a 0x07)
printf -v cpu_res "%d" "$cpu_temp"
if [[ $cpu_res -lt $cpu_high && $hdd_temp -lt $hdd_high ]]; then
#echo "CPU und HDD Temperaturen in Ordnung"
sleep 30
else
halt
fi
else
cpu_temp=$(i2cget -y 0x0 0x0a 0x07)
printf -v cpu_res "%d" "$cpu_temp"
if [ $cpu_res -lt $cpu_high ]; then
#echo "CPU Temperatur in Ordnung - HDD im Standby Modus"
sleep 30
else
halt
fi
fi
done
}
case $1 in
start)
[ -f $PIDFILE ] && [ -f /proc/` cat $PIDFILE `/cmdline ] && echo "already running. Aborting." && exit 1
$0 background &
echo "Starting $NAME..."
;;
stop)
kill -9 ` cat $PIDFILE ` >/dev/null 2>&1
echo "Stopping $NAME ` cat $PIDFILE ` "
;;
status)
[ -f $PIDFILE ] && [ -f /proc/` cat $PIDFILE `/cmdline ] && echo "running as ` cat $PIDFILE ` " && exit 0
echo "not running"
;;
background)
Background
;;
*)
echo "use $0 [ start | stop | status ]"
;;
esac
任何幫助表示讚賞
乾杯 莫里茨
錯誤信息究竟是什麼? –
您的腳本名稱是否在您的路徑中? – BroSlow
/bin/sh $ 0背景&<-----做了詭計!謝謝@Olaf Dietsche – Moritz