今天寫了個腳本,過不了錯誤這一關,求大神路過瞟一眼。 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/ ...
今天寫了個腳本,過不了錯誤這一關,求大神路過瞟一眼。
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:\n${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