Shell while read

#!/bin/bash
set -x

function rm OldRelease(){
    awk -F "/" '{print $13}' release.log >> tmp.txt

    while read line || [[ -n $line ]]
    do
        if [ ${line} ];then
            rm -rf ${line}
            sed -i "/${line}/d" release.log
        fi
    done < tmp.txt

    if [ -f tmp.txt ];then
        rm -f tmp.txt
    fi
    
    sed -i '$!d' release.log
}

ls -l |awk '{print $9}' |grep -v "^$" >dirList.txt

while read line || [[ -n $line ]]
do
    if [[ ${line} =~ ^HiCloud.*$ ]];then
        pushd /opt/hw/release/hitouch/${line}
        rmOldRelease
        popd
    fi
done < dirList.txt

rm -f dirList.txt

release.log 

2018-11-29:16:22:06 install 1.1.0.38.20181129161838 /opt/hw/release/hitouch/HiTouchCloud_CDps/20181129162206 taskid: 877f3dfd1c974e9a9ba119b8ecfb061b backup_path: None
2018-12-04:18:35:10 install 1.1.0.38.20181129161838 /opt/hw/release/hitouch/HiTouchCloud_CDps/20181204183510 taskid: 96982981aab147988f2461bd9f5a9995 backup_path: /opt/hw/release/hitouch/HiTouchCloud_CDps/20181129162206
2018-12-04:20:31:52 install 1.1.0.38.20181204202758 /opt/hw/release/hitouch/HiTouchCloud_CDps/20181204203152 taskid: b919f2a51bc14893a0edcc940a699b50 backup_path: /opt/hw/release/hitouch/HiTouchCloud_CDps/20181204183510
2018-12-04:20:34:32 install 1.1.0.38.20181204202758 /opt/hw/release/hitouch/HiTouchCloud_CDps/20181204203432 taskid: 3f3139430c0d4d74b0eca60e237df7a5 backup_path: /opt/hw/release/hitouch/HiTouchCloud_CDps/20181204203152

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值