zoukankan      html  css  js  c++  java
  • 将批量指定的docker镜像打成文件

     
    #/bin/bash
    tag=20180816
    img1=hub.chinacloud.com.cn/onex.dev/one-task-scheduler:$tag
    img2=hub.chinacloud.com.cn/onex.dev/one-route:$tag
    img3=hub.chinacloud.com.cn/onex.dev/one-infrastructure-api:$tag
    img4=hub.chinacloud.com.cn/onex.dev/one-logging-api:$tag
    img5=hub.chinacloud.com.cn/onex.dev/one-config:pro-$tag
    img6=hub.chinacloud.com.cn/onex.dev/keycloak:3.4.0.Final.$tag
    img7=hub.chinacloud.com.cn/onex.dev/one-registry:$tag
    img8=hub.chinacloud.com.cn/fast-wh.dev/whitehole-business:$tag
    img9=hub.chinacloud.com.cn/fast-wh.dev/whitehole-event:$tag
    img10=hub.chinacloud.com.cn/fast-wh.dev/whitehole-flow:$tag
    img11=hub.chinacloud.com.cn/fast-pulsar.dev/westoneui-all-in-one:$tag
    img12=hub.chinacloud.com.cn/fast-pulsar.dev/pulsar-ui:$tag
    img13=hub.chinacloud.com.cn/fast-pulsar.dev/pulsar:$tag
    img14=hub.chinacloud.com.cn/fast-pulsar.dev/pulsar-sidecar:$tag
    
    images=($img1 $img2 $img3 $img4 $img5 $img6 $img7 $img8 $img9 $img10 $img11 $img12 $img13 $img14)
    
    for each in ${images[@]}; do
      docker pull $each
      array=(${each//// })
      for var in ${array[@]}; do
        if [[ $var =~ ":" ]]; then
          tar=`echo $var | cut -d ':' -f 1`
          docker save -o ${tar}.tar $each
          tar cjvf ${tar}.tbz ${tar}.tar
          rm -rf ${tar}.tar
        fi
      done
    done

    1、(${each//// })  将字符串按/ 进行拆分,写成/主要是是/的转义字符,按什么拆分可以写成 (${each//分割符/}),比如下面按 "-"进行拆分

    a="one-two-three-four"
    #要将$a分割开,可以这样:"
    arr=(${a//-/ })
    for s in ${arr[@]}
    do
        echo "$s" 
    done

    执行后显示:

    one
    two
    three
    four

    2、如果匹配冒号

    if [[ $var =~ ":" ]];

    上面这句的意思是如果$var表示的字符串中匹配 “:”。

    比如面的例子

    $ cat 123.sh 
    #!/bin/bash
    
    read -p "Please type :" x
    if [[ $x =~ "[0-9]" ]];then
            echo "yes"
    else
            echo "no"
    fi
    $ ./123.sh 
    Please type :1
    yes
    $ ./123.sh 
    Please type :f
    no

    3、cut用法

    cut语法
    
    [root@www ~]# cut -d'分隔字符' -f fields <==用于有特定分隔字符
    [root@www ~]# cut -c 字符区间            <==用于排列整齐的信息
    选项与参数:
    -d  :后面接分隔字符。与 -f 一起使用;
    -f  :依据 -d 的分隔字符将一段信息分割成为数段,用 -f 取出第几段的意思;
    -c  :以字符 (characters) 的单位取出固定字符区间;
     
    
    PATH 变量如下
    
    [root@www ~]# echo $PATH
    /bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:/usr/games
    # 1 | 2       | 3   | 4       | 5            | 6            | 7
     
    
    将 PATH 变量取出,我要找出第五个路径。
    
    #echo $PATH | cut -d ':' -f 5
    /usr/local/bin
     
    
    将 PATH 变量取出,我要找出第三和第五个路径。
    
    #echo $PATH | cut -d ':' -f 3,5
    /sbin:/usr/local/bin
     
    
    将 PATH 变量取出,我要找出第三到最后一个路径。
    
    echo $PATH | cut -d ':' -f 3-
    /sbin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:/usr/games
     
    
    将 PATH 变量取出,我要找出第一到第三个路径。
    
    #echo $PATH | cut -d ':' -f 1-3
    /bin:/usr/bin:/sbin:
     
     
    
    将 PATH 变量取出,我要找出第一到第三,还有第五个路径。
    
    echo $PATH | cut -d ':' -f 1-3,5
    /bin:/usr/bin:/sbin:/usr/local/bin
     
    
    实用例子:只显示/etc/passwd的用户和shell
    
    #cat /etc/passwd | cut -d ':' -f 1,7 
    root:/bin/bash
    daemon:/bin/sh
    bin:/bin/sh
    
  • 相关阅读:
    paper:synthesizable finit state machine design techniques using the new systemverilog 3.0 enhancements之output encoded style with registered outputs(Good style)
    软测(一)
    package.json
    邬江兴:网络安全“再平衡战略”抓手--拟态防御
    什么是DDOS攻击?怎么防御?
    什么是gitlab CI ?CI代表什么?
    结构体字节对齐(转)
    MySQL 及 SQL 注入与防范方法
    HDU 4704 Sum (费马小定理)
    HDU 4704 Sum (费马小定理)
  • 原文地址:https://www.cnblogs.com/boshen-hzb/p/9482224.html
Copyright © 2011-2022 走看看