如何在 ssh 命令中使用heredoc

如何在 ssh 命令中使用heredoc

我有一个 bash 脚本,它通过 SSH 连接到远程计算机并运行一系列命令。

外部脚本中的heredoc似乎没有正确对齐,并且我不断收到错误。

-bash: line 49: warning: here-document at line 6 delimited by end-of-file (wanted `MOD')

这是脚本:

ssh -i "$master_private_key" "$master_username@$master_public_ip" << EOF
    # disable swap
    sudo swapoff -a
    sudo sed -i '/swap/ s/^/#/' /etc/fstab

    # setup the bridge for IPV4
    cat <<- MOD | sudo tee /etc/modules-load.d/k8s.conf
        overlay
        br_netfilter
    MOD
    sudo modprobe overlay
    sudo modprobe br_netfilter

    # sysctl params required by setup, params persist across reboots
    cat <<- MOD | sudo tee /etc/sysctl.d/k8s.conf
        net.bridge.bridge-nf-call-iptables = 1
        net.bridge.bridge-nf-call-ip6tables = 1
        net.ipv4.ip_forward = 1
    MOD

    # Apply sysclt parameters without reboot
    sudo sysctl --system

    sudo apt-get update && apt install docker.io -y
    sudo apt-get update 
    sudo apt-get install -y apt-transport-https ca-certificates curl
    sudo mkdir /etc/apt/keyrings
    sudo curl -fsSLo /etc/apt/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
    echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
    sudo apt-get update
    sudo apt-get install -y kubelet kubeadm kubectl
    sudo apt-mark hold kubelet kubeadm kubectl

    
    # initialize kubeadm on master
    kubeadm init --pod-network-cidir=192.168.0.0/16 --ignore-preflight-errors=all

    mkdir -p $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    sudo chown $(id -u):$(id -g) $HOME/.kube/config

    # install calico SDN
    kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/tigera-operator.yaml
    curl https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/custom-resources.yaml -O
    kubectl create -f custom-resources.yaml

    # Get the join command
    $JOIN_COMMAND=$(kubeadm token create --print-join-command)
    export $JOIN_COMMAND
    
EOF

我希望有人能指出这个问题。

相关内容