在此bash脚本中,服务器列表包含应计算磁盘空间的所有服务器列表。它们的范围从c1到c109。现在,来自c100-c109的服务器的容量低于50%,因此我必须获得以下消息
“有足够的可用磁盘空间”
但是,我得到的却是这个信息
“我运行的磁盘空间似乎不存在”
如果有人能帮我解决这个问题,那就太棒了。如果你需要任何澄清,请告诉我。下面是脚本:
#!/usr/bin/bash
# This script does a very simple test for checking disk space.
for VTIER in `cat serverlist`
do
space=$(ssh -q ${VTIER}@${VTIER} 'df -kh|grep ${ServerName}|cut -c 65-70')
echo "Checking disk space.... in ${VTIER}"
case $space in
[1-6]*)
Message="There is sufficient disk space available - $space full"
;;
[7-8]*)
Message="Keep an eye on the disk space - $space full."
;;
9[1-8])
Message="Better hurry with that new disk - $space full."
;;
99)
Message="I'm drowning here! - $space full"
;;
*)
Message="I seem to be running with an nonexistent amount of disk space - $space full"
;;
esac
echo $Message
done发布于 2013-05-10 03:08:09
您的切割不正确:
marc@panic:/home/httpd/html$ df -kh|cut -c 65-70
marc@panic:/home/httpd/html$注意空行...这不仅仅是空格。这是截取的输出。一旦包含强制块大小的k选项,块大小列就会被删除,从而缩短每一行,因此实际上是从每行结束处开始剪切文本。使用awk可能会更好:
marc@panic:/home/httpd/html$ df -kh|awk '{print $5}'
Use%
7%
1%
1%
0%
1%
61%https://stackoverflow.com/questions/16469184
复制相似问题