将批量指定的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

 

 

 

一、(${each//\// })  将字符串按/ 进行拆分,写成\/主要是是/的转义字符,按什么拆分能够写成 (${each//分割符/}),好比下面按 "-"进行拆分docker

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

执行后显示:shell

one two three four

 

二、若是匹配冒号api

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

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

好比面的例子ui

$ 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

 

三、cut用法spa

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 
相关文章
相关标签/搜索