我设法让这个脚本更早地工作,但后来它停止工作,现在我总是收到这个错误,日志不显示任何信息 .log 文件为空
在我将 { df -k ${fileSystem}|tail -n1 } 更改为 { quota -u |tail -n1 } 之前,我的脚本运行良好,因为它显示了分配给我的正确用法,而不是整个种子箱
- 检查整个 Seedbox 磁盘是否可用
user@hera:~/scripts$ df -k /home20/<user>|tail -n1
/dev/sdu1      15616058976 3311158640 12303321368  22% /home20
- 检查 Seedbox Slot only disk free
user@hera:~/scripts$ quota -u <user>|tail -n1
      /dev/sdu1 1629501728  1953497088 1953497088            4344       0       0
- 日志文件
tail: deluge-disk-check.log: file truncated
[empty]
- 错误信息
./deluge-disk-check.sh: line 23: let: freeSpacePct=100*/: syntax error: operand expected (error token is "/")
我的脚本
#!/bin/bash
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>/home/<user>/scripts/deluge-disk-check.log 2>&1
# Adjust these parameters to your system
fileSystem="/home/<user>"     # Filesystem you want to monitor
minFreeSpace1="78"   # Seedbox Free space 1st threshold percentage
minFreeSpace2="77"   # Seedbox Free space 2nd threshold percentage
checkInterval="3600"     # Interval between checks in seconds
SERVICE='deluged'
  while (:); do
    # Get the output of df -k and put in a variable for parsing
       dfOutPut=$(df -k ${fileSystem}|tail -n1)
    # Exctract the fields containing total and available 1K-blocks
       totalBlocksKb=$(echo "${dfOutPut}" | awk '{print $2}')
       availableBlocksKb=$(echo "${dfOutPut}" | awk '{print $4}')
    # Calculate percentage of free space
    let freeSpacePct=100\*${availableBlocksKb}/${totalBlocksKb}
    # Check if free space percentage is below threshold value
    if [ "${freeSpacePct}" -lt "${minFreeSpace1}" ]; then
       date +'%Y-%m-%d %H:%M:%S'
       echo "You only have ${freeSpacePct}% free space on seedbox"
   # Check whether the instance of thread exists:
    if ps ax | grep -v grep | grep $SERVICE > /dev/null
  then
       echo "Deluge is running, Is there free space on device?"
       pkill deluge
       echo -e "No, Trying to stop Deluge...\nDeluge stopped, exiting"
  else
   if [ "${freeSpacePct}" -lt "${minFreeSpace2}" ]; then
       echo "refreshing data..."
       echo "Deluge is not running, Is there free space on device?"
       echo "Yes, Threshold value is now ${minFreeSpace2}%"
       echo "Trying to restart Deluge ..." && app-deluge restart
       echo "Deluge is running, exiting"
    sleep ${checkInterval}
    fi
  fi
fi
done