shell脚本执行已有的其他脚本文件

工作中常遇到一些数据问题,需要各种脚本去处理,各种先后顺序,还要处理多个库,还会遇到某个脚本处理某个库时报错需要重新处理的问题,因此用一个shell把它们串起来就比较方便了

1.多个库执行同一个脚本

#/bin/bash
city_array=('bj' 'sh' 'tj' )
type="test"
for city in ${city_array[@]};
do
    echo $city
    sh sync_test.sh $city ${type}"_"${city} 
done

2.多个库执行同一个脚本(test_run.py),将多个城市库名称写入另一个文件(nxm_newsell_0816.txt),执行当前shell时,从nxm_newsell_0816.txt中读取城市库名称,读取完即删除,以备当test_run.py执行时某个城市失败,将异常城市追加到新生成的nxm_newsell_0816.txt,下次执行当前shell时,只执行上次失败的城市
注:
nxm_newsell_0816.txt 中的内容格式: bj,sh,tj
test_run.py 失败记录方式
在这里插入图片描述

    #/bin/bash
    str=$(cat nxm_newsell_0816.txt)
    #以逗号分割字符串为数组
    str=${str//,/ }  
    city_array=($str)
    rm -rf 'nxm_newsell_0816.txt'
    for city in ${city_array[@]};
    do
        echo $city
        python test_run.py $city
    done

猜你喜欢

转载自blog.csdn.net/weixin_43697585/article/details/84144984
今日推荐