在不同虚拟机上的脚本中调用多个Shell脚本

时间:2018-07-07 03:41:09

标签: linux shell ubuntu

我正在尝试创建将在一个VM中安装Zookeeper Server并将其对应的Zookeeper客户端安装在不同VM中的Shell脚本,因此我编写了如下的Shell脚本

#!/bin/bash

ZOOKEEPER_SERVER_IP="1.2.3.4"

while read  ipaddress zookeepertype number
do

        echo -e "Setting up the Zookeepers \n"

        echo $ipaddress

        if [ "${zookeepertype}" = 'zookeeperserver' ]; then

                echo "Setup Zookeeper Server"

                        #ZOOKEEPER_SERVER_IP = $ipaddress

                        #echo $ZOOKEEPER_SERVER_IP

                        #echo $ipaddress

                        sudo scp -i /home/ubuntu/.ssh/fd -r /home/ubuntu/ZooKeeper_Server_Script.sh ubuntu@$ipaddress:/home/ubuntu/

                        ssh -i /home/ubuntu/.ssh/fd ubuntu@$ipaddress /home/ubuntu/ZooKeeper_Server_Script.sh

                        echo "This script is about to run ZooKeeper_Server_Script."

                        echo "The server script has completed.";

                       #sleep 30

                        exit 1

       fi

        echo -e $ZOOKEEPER_SERVER_IP

        if [ $zookeepertype = "zookeeperclient" ] ; then

                        echo "Setup Zookeeper Client"

                        echo $ipaddress

                        sudo scp -i /home/ubuntu/.ssh/fd -r /home/ubuntu/ZooKeeper_Client_Script.sh ubuntu@$ipaddress:/home/ubuntu/

                        ssh -i /home/ubuntu/.ssh/fd ubuntu@$ipaddress

                        #mkdir /home/ubuntu/keyfiles

                        #exit


                        #sudo scp -i /home/ubuntu/.ssh/fd -r /home/ubuntu/abc/network/test/keyfiles/* ubuntu@$ipaddress:/home/ubuntu/keyfiles

                        #sudo scp -i /home/ubuntu/.ssh/fd -r /home/ubuntu/abc/test/simple/abc.json ubuntu@$ipaddress:/home/ubuntu/

                        #ssh -i /home/ubuntu/.ssh/fd ubuntu@$ipaddress

                        #chmod 777 ZooKeeper_Client_Script.sh

                        #echo "This script is about to run ZooKeeper_Client_Script."

                        #sh ./ZooKeeper_Client_Script.sh $ZOOKEEPER_SERVER_IP

                        echo "The client script has completed."

                        #exit

                fi

        #Separating Runhosts File

done < setupZkinput.txt

输入文件是 1.2.3.4 zookeeperserver 1 5.6.7.8 zookeeperclient 2 9.10.11.12 zookeeperclient 3

我面临的问题是

1)仅完成服务器设置,即脚本在第一行之后退出 2)无法在ZOOKEEPER_SERVER_IP = $ ipaddress行中动态分配服务器ip

谢谢

1 个答案:

答案 0 :(得分:0)

将文件复制到服务器后,要设置的默认权限是什么? 记住它需要执行权限才能执行脚本。