【发布时间】:2014-10-06 01:05:10
【问题描述】:
您好,正在处理 bash 脚本,该脚本将 ssh 到多个盒子并执行一些磁盘空间清理命令。我正在使用 find 并且 ssh 是无密码的。我在列表中大约有 10 个框。但我在逻辑上失败了。这是代码:
#!/bin/bash
#cleanup_paths
NUMLINE=$(cat /hostnames.txt|wc -l)
SERVER_LIST=/hostnames.txt
CPATH1=/random_files
CPATH2=/random_files1
CPATH3=/random_files2
CPATH4=/random_files3
CPATH5=/random_files4
CPATH6=/random_files5
CPATH7=/random_files6
MAX_DISK=86
while read line;
do
ssh $line
CURRENT_USAGE=$(df -h|grep /home|awk '{print $4}'|sed 's/%//')
cleanup_engage(){
if [ $CURRENT_USAGE -ge $MAX_DISK ]; then
return 1
else
return 0
fi
}
cleanup_engage
if [ "$?" -eq "1" ]; then
find $CPATH1 -type f -name '*.log' -mtime +3 -exec rm -f {} \;
sleep 20
find $CPATH2 -maxdepth 1 -type d -name 'FTS*' -mtime +5 -exec rm -rf {} \;
sleep 30
find $CPATH3 -type f -name '*.log' -mtime +5 -exec rm -f {} \;
sleep 5
find $CPATH4 -type f -name '*.log' -mtime +5 -exec rm -f {} \;
sleep 5
find $CPATH5 -type f -name '*.log' -mtime +5 -exec rm -f {} \;
sleep 5
find $CPATH6 -type f -name '*.log' -mtime +5 -exec rm -f {} \;
sleep 5
find $CPATH7 -type f -name '*LOG*' -mtime +5 -exec rm -f {} \;
sleep 10
/usr/bin/sendmail stack@stack.com<<EOF
subject:
EOF
else
exit 0
fi
((NUMLINE++))
done < $SERVER_LIST
【问题讨论】:
标签: bash unix ssh batch-processing