0
您好在處理將ssh運行到多個框並執行一些磁盤空間清理命令的bash腳本。我使用find和ssh是無密碼的。列表中有大約10個框。但我的邏輯失敗了。下面是代碼:在BASH中的不同主機上通過ssh運行多個find命令
#!/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 [email protected]<<EOF
subject:
EOF
else
exit 0
fi
((NUMLINE++))
done < $SERVER_LIST