shell脚本,将固件从服务器导出到本地

项目末尾,有了一点空闲时间,打算把自己之前想做的事情做一下。

之前,我们每次编译版本后,都要到服务器对应的目录下,找到对应的固件,将固件用一个规范的名字(姓名+日期+固件类型+第几个)打包并拷贝到ftp下传到本地。

现在可以用一个脚本实现此功能:

#!/bin/sh
#DATE:2019.01.31
#The function is designed for Dakota.(copy the img from the server to the Desktop)
#Designed by aizhaung.zhou
DATE=$(date +%Y.%m.%d)
TIME=$(date +%H.%M.%S)

product_name=$1
if [ ! -n "$product_name" ]; then
    echo "try: ./down MA8K (If you want to download firmware of MA8K)"
    echo "try: ./down TA   (If you want to download firmware of TA)"
    echo "try: ./down TB   (If you want to download firmware of TB)"
    exit 1
fi

imgname=""
if [ "$product_name" = "MA8K" ]; then
    cd ./products/Dakota_MA8K/images
    imgname=`ls | grep MA8K_ | tail -1`
elif [ "$product_name" = "TA" ]; then
    cd ./products/Dakota_TA/images
    imgname=`ls | grep TA8K_ | tail -1`
elif [ "$product_name" = "TB" ]; then
    cd ./products/Dakota_TB/images
    imgname=`ls | grep Bridge_ | tail -1`
fi

if [ ! -n "$imgname" ]; then
    cd ./products/
    passname=`pwd`"/"$1
    echo "There is no firmware in: $passname"
    exit 1
else
    str=${imgname:0:7}
    version=${str%_*}
    if [ "$version" = "Bridge" ]; then
        version="TB"
    fi
    ####################change the name for yourself########################
    tarname="image_"$DATE"_aizhuang.zhou_"$TIME"_"$version". tar. gz"
    #tarname="image_"$DATE"xxx.yang_"$TIME"_"$version". tar. gz"
    #tarname="image_"$DATE"xxx.li_"$TIME"_"$version". tar. gz"
    #tarname="image_"$DATE"xxx.zhang_"$TIME"_"$version". tar. gz"
    ###################################################################
    tar -zcf "$tarname" "$imgname"
    mv "$tarname" /home/image/download
    echo "Download "$tarname" success!"
    #rm .
fi

1、用户只需要执行./down TA类似这样的语句就可以到对应的目录下打包固件,导出

2、用户不会使用的话,有提示

3、导出成功有打印提示信息,包括固件的名称,以便于到ftp查找

4、命名自动获取了时间和日期,永远不会起重复的名字。

5、还可以再添加功能,比如说,定期读取secureCRT的日志,当读取到最后一行的信息为编译成功的提示,将固件导出。这个只需要将代码移植到makefile中理论上可实现。

posted @ 2019-03-05 11:28  进心进利  阅读(382)  评论(0编辑  收藏  举报