HP-Unix:C-shell:Disk space 检查
HP-Unix: C-shell:Disk space checking
我有 10 个使用 hp-ux 的设备,我想检查每个设备中的磁盘 space。
我的要求是如果 space 超过 90%,设备 ans space 的信息将被保存到日志中。
这是我设置为变量 ipadd 的设备和 IP 地址列表:
lo1 100.45.32.43
lot2 100.45.32.44
lot3 100.45.32.44
lot4 100.45.32.45
lot5 100.45.32.46
and so on..
到目前为止,这是我的脚本:
#!/bin/csh -f
set ipaddress = (`awk '{print }' "ipadd"`)
set device = (`awk '{print }' "ipadd"`)
@ j = 1
while ($j <= $#ipaddress)
echo $ipaddress
set i = 90 # Threshold set at 90%
set max = 100
while ($i <= $max)
rsh $ipaddress[$j] bdf | grep /dev/vg00 | grep $i% \
|awk '{ file=substr(,index(,"/") + 1,length()); print "WARNING: $device[$j]:/" file " has reached " ". Perform HouseKeeping IMMEDIATELY..." >> "/scripts/space." file ".file"}'
@ i++
end
@ j++
end
bdf后的输出:
/dev/vg00/lvol2 15300207 10924582 28566314 79% /
/dev/vg00/lvol4 42529 23786 25510 55% /stand
执行脚本后终端输出:
100.45.32.43
100.45.32.44
.file 的输出:
WARNING: $device[$j]:/ has reached 79%. Perform HouseKeeping IMMEDIATELY...
我的问题是,是不是我的循环出了问题,因为我的 .file 输出只显示了一个设备,所以只迭代了一次?
为什么 $device[$j] 没有出现在 .file 输出中?
或 awk 有问题吗?
谢谢你的建议。
您的代码针对 90 到 100 之间的每个可能百分比进行了测试。
大概,您可以接受检查一次并询问 'is device percent greater than 90%'? 的代码。那么你根本不需要内部循环,每台机器只建立 1 个连接,try
#!/bin/csh -f
set ipaddress = (`awk '{print }' "ipadd"`)
set device = (`awk '{print }' "ipadd"`)
@ j = 1
set i = 90 # Threshold set at 90%
while ($j <= $#ipaddress)
echo $ipaddress
echo "#dbg: ipaddress[$j]=${ibpaddress[$j]}"
rsh $ipaddress[$j] bdf \
| awk -v thresh="$i" -v dev="$device[$j]" \
'/\/dev\/vg00/ { \
sub(/%/,"",) \
if ( > thresh) { \
file=substr(,index(,"/") + 1,length()) \
print "WARNING: " dev ":/" file " has reached " ". Perform HouseKeeping IMMEDIATELY..." >> "/scripts/space." file ".file" \
}\
}'
@ j++
end
抱歉,我没有 csh
可用于 dbl-chk 的语法错误。
所以这是我们确定在您的环境中有效的一个衬垫。
rsh $ipaddress[$j] bdf | nawk -v thresh="$i" -v dev="$device[$j]" '/\/dev\/vg00/ { sub(/%/,"",) ; if ( > thresh) { file=substr(,index(,"/") + 1,length());print "#dbg:file="file; print "WARNING: " dev ":/" file " has reached " ". Perform HouseKeeping IMMEDIATELY..." >> "/scripts/space.file.TMP" } }'
我没有 bdf
可用的系统。在 sub()
和 if
测试中更改对 </code> 的两个引用,以匹配具有您要测试的百分比的输出的字段编号。</p>
<p>请注意,<code>-v var="value"
是将变量值从 shell 传递到用单引号括起来的 awk
脚本的标准方法。
注意行尾的任何 '\' 字符 都是 最后的字符,没有尾随 space 或制表符,否则你会得到一个无法辨认的错误信息。 ;-)
IHTH
我有 10 个使用 hp-ux 的设备,我想检查每个设备中的磁盘 space。 我的要求是如果 space 超过 90%,设备 ans space 的信息将被保存到日志中。 这是我设置为变量 ipadd 的设备和 IP 地址列表:
lo1 100.45.32.43
lot2 100.45.32.44
lot3 100.45.32.44
lot4 100.45.32.45
lot5 100.45.32.46
and so on..
到目前为止,这是我的脚本:
#!/bin/csh -f
set ipaddress = (`awk '{print }' "ipadd"`)
set device = (`awk '{print }' "ipadd"`)
@ j = 1
while ($j <= $#ipaddress)
echo $ipaddress
set i = 90 # Threshold set at 90%
set max = 100
while ($i <= $max)
rsh $ipaddress[$j] bdf | grep /dev/vg00 | grep $i% \
|awk '{ file=substr(,index(,"/") + 1,length()); print "WARNING: $device[$j]:/" file " has reached " ". Perform HouseKeeping IMMEDIATELY..." >> "/scripts/space." file ".file"}'
@ i++
end
@ j++
end
bdf后的输出:
/dev/vg00/lvol2 15300207 10924582 28566314 79% /
/dev/vg00/lvol4 42529 23786 25510 55% /stand
执行脚本后终端输出:
100.45.32.43
100.45.32.44
.file 的输出:
WARNING: $device[$j]:/ has reached 79%. Perform HouseKeeping IMMEDIATELY...
我的问题是,是不是我的循环出了问题,因为我的 .file 输出只显示了一个设备,所以只迭代了一次? 为什么 $device[$j] 没有出现在 .file 输出中? 或 awk 有问题吗?
谢谢你的建议。
您的代码针对 90 到 100 之间的每个可能百分比进行了测试。
大概,您可以接受检查一次并询问 'is device percent greater than 90%'? 的代码。那么你根本不需要内部循环,每台机器只建立 1 个连接,try
#!/bin/csh -f
set ipaddress = (`awk '{print }' "ipadd"`)
set device = (`awk '{print }' "ipadd"`)
@ j = 1
set i = 90 # Threshold set at 90%
while ($j <= $#ipaddress)
echo $ipaddress
echo "#dbg: ipaddress[$j]=${ibpaddress[$j]}"
rsh $ipaddress[$j] bdf \
| awk -v thresh="$i" -v dev="$device[$j]" \
'/\/dev\/vg00/ { \
sub(/%/,"",) \
if ( > thresh) { \
file=substr(,index(,"/") + 1,length()) \
print "WARNING: " dev ":/" file " has reached " ". Perform HouseKeeping IMMEDIATELY..." >> "/scripts/space." file ".file" \
}\
}'
@ j++
end
抱歉,我没有 csh
可用于 dbl-chk 的语法错误。
所以这是我们确定在您的环境中有效的一个衬垫。
rsh $ipaddress[$j] bdf | nawk -v thresh="$i" -v dev="$device[$j]" '/\/dev\/vg00/ { sub(/%/,"",) ; if ( > thresh) { file=substr(,index(,"/") + 1,length());print "#dbg:file="file; print "WARNING: " dev ":/" file " has reached " ". Perform HouseKeeping IMMEDIATELY..." >> "/scripts/space.file.TMP" } }'
我没有 bdf
可用的系统。在 sub()
和 if
测试中更改对 </code> 的两个引用,以匹配具有您要测试的百分比的输出的字段编号。</p>
<p>请注意,<code>-v var="value"
是将变量值从 shell 传递到用单引号括起来的 awk
脚本的标准方法。
注意行尾的任何 '\' 字符 都是 最后的字符,没有尾随 space 或制表符,否则你会得到一个无法辨认的错误信息。 ;-)
IHTH