今天写了个脚本,过不了错误这一关,求大神路过瞟一眼。
1 #!/bin/bash
2 #disk use
3 disk_use() {
4 DISK_LOG=/tmp/disk_use.tmp
5 DISK_TOTAL=`fdisk -l |awk '/^Disk.*bytes/ &&//dev/{print $2" ";printf "%d",$3;print "GB"}'`
6 USER_RATE=`df -h |awk '/^/dev/{print int($5)}'`
7 }
8 disk_use
9 for i in "$USER_RATE"
10 do
11 if [ $i -gt 90 ] &>/dev/null;then
12 PART=`df -h |awk '{if(int($5)=='''$i'''){print $6}}'`
13 echo "$PART = $i" >> $DISK_LOG
14 fi
15 done
16 echo "-------------------------------------"
17 echo -e "Disk total:
${DISK_TOTAL}"
18 if [ -f $DISK_LOG ];then
19 echo "------------------------------"
20 cat $DISK_LOG
21 echo "------------------------------"
22 rm -f $DISK_LOG
23 else
24 echo "------------------------------"
25 echo "disk use rate no than 90% of the partition."
26 echo "------------------------------"
27 fi
不加&>/dev/null就一直提示错误,好像表达式也没问题?
错误提示:(变量和90加不加双引号都这个)
[root@localhost ~]# ./disk_use.sh
./disk_use.sh: line 11: ((: >= 90 : syntax error: operand expected (error token is ">= 90 ")
。。。。。。。。。。。。
改用 if [ "$i" -gt 90 ]
提示:
[root@localhost ~]# ./disk_use.sh
./disk_use.sh: line 11: [: : integer expression expected
不用双引号:
[root@localhost ~]# ./disk_use.sh
./disk_use.sh: line 11: [: -gt: unary operator expected