1. 程式人生 > >ssh執行遠程命令和bash -c string的用法

ssh執行遠程命令和bash -c string的用法

sign -m sla mysql conf follow exit ash hub

ssh執行遠程命令和bash -c string的用法
說明:
今天在學習k8s的Run a Replicated Stateful Application (運行一個有狀態應用的副本)時,官網上給出StatefulSet yaml配置文件中出現如下內容:

spec:
      initContainers:
      - name: init-mysql
        image: mysql:5.7
        command:
        - bash
        - "-c"
        - |
          set -ex
          # Generate mysql server-id from pod ordinal index.
          [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
          ordinal=${BASH_REMATCH[1]}
          echo [mysqld] > /mnt/conf.d/server-id.cnf
          # Add an offset to avoid reserved server-id=0 value.
          echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
          # Copy appropriate conf.d files from config-map to emptyDir.
          if [[ $ordinal -eq 0 ]]; then
            cp /mnt/config-map/master.cnf /mnt/conf.d/
          else
            cp /mnt/config-map/slave.cnf /mnt/conf.d/
          fi

其中的bash -c有些不明白,所以man bash查看下:

-c string If the -c option is present, then commands are read from string.  If there are arguments after the string, they are assigned to the positional parameters,  starting
                 with $0.

參考文檔:
http://baohaojun.github.io/blog/2013/12/11/0-ssh-remote-command-and-bash--c-string.html

ssh執行遠程命令和bash -c string的用法