一键清理日志脚本

2018/07/30 14:21
阅读数 22

#!/bin/bash
DATE=$(date +"%Y-%m-%d %T")
> /home/jenkins/ansible-playbook/cleardisk/homespace.txt
> /home/jenkins/ansible-playbook/cleardisk/dxslog_IP.txt
for i in $(cat clearIP.txt)
do
x=$(ssh imt@$i "df -h|grep /home\$ | awk '{print \$5}'|awk -F '%' '{print \$1}'")
echo $x $i >> /home/jenkins/ansible-playbook/cleardisk/homespace.txt
y=$(ssh imt@$i "crontab -l|grep "dxs/crontab" | awk -F';|>>' '{print \$2;}'|head -n 1")
# echo $y
z=$y/log
echo "$DATE $i $z Home directory space is %$x"
echo $z $i >> /home/jenkins/ansible-playbook/cleardisk/dxslog_IP.txt
if [ "$x" -ge 90 ]
then
ssh imt@$i "$z;rm -f *.*"
fi

done
ssh imt@172.17.192.176 "cd /home/imt/dxs/Log && rm -rf *"
ssh imt@200.31.156.104 "cd /home/imt/RMBMSS_dxs/log && rm -rf *"
ssh imt@200.31.156.103 "cd /home/imt/RMBMSS_dxs/log && rm -rf *"
ssh imt@172.17.192.110 "cd /home/imt/dxs/log && rm -rf *"
ssh imt@172.17.193.35 "cd /home/imt/dxs/log && rm -rf *"

注意要将远程的变量拿到本地作比较

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部