脚本注释:

PS:用PYTHON2.6的master

#!/bin/sh

source /etc/profile

yum list installed | grep salt-minion

install_status=`echo $?`

localhostname=`hostname`

if [ $install_status == 0 ];then

        saltid=`cat /etc/salt/minion | grep -v '#' | grep id | sed 's/id: //g'`

        if [ "$saltid" == "$localhostname" ];then

                service salt-minion status

        runstatus=`echo $?`

                if [ $runstatus != 0 ];then

            echo "salt-minion is running"

                        exit 0

                else

                        service salt-minion start

                        service salt-minion status

            runstatus=`echo $?`

                        if [ $runstatus == 0 ];then

                echo "salt-minion start sucessfully"

                                exit 0

                        else

                echo "salt-minion start fail"

                                exit 0

                        fi

                fi

        else

                mv /etc/salt/minion /etc/salt/minion_bak

                echo "id: "$localhostname >> /etc/salt/minion

                echo "user: root" >> /etc/salt/minion

                echo "master : 10.7.7.180" >> /etc/salt/minion

                echo "master_port: 4506" >> /etc/salt/minion

                echo "backup_mode: minion" >> /etc/salt/minion

                echo "output: nested" >> /etc/salt/minion

                echo "acceptance_wait_time: 10" >> /etc/salt/minion

                echo "acceptance_wait_time_max: 0" >> /etc/salt/minion

                echo "random_reauth_delay: 60" >> /etc/salt/minion

                service salt-minion status

        runstatus=`echo $?`

                if [ $runstatus == 0 ];then

                        service salt-minion restart

                        service salt-minion status

            runstatus=`echo $?`

                        if [ $runstatus == 0 ];then

                echo "salt-minion restart sucessfully"

                                exit 0

                        else

                echo "salt-minion restart fail"

                                exit 0

                        fi

                else

                        service salt-minion start

                        service salt-minion status

            runstatus=`echo $?`

                        if [ $runstatus == 0 ];then

                echo "salt-minion start sucessfully"

                                exit 0

                        else

                echo "salt-minion start fail"

                                exit 0

                        fi

                fi

        fi

else

        rpm -Uvh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm

        yum install -y salt-minion

        mv /etc/salt/minion /etc/salt/minion_bak

        echo "id: "$localhostname >> /etc/salt/minion

        echo "user: root" >> /etc/salt/minion

        echo "master : 10.7.7.180" >> /etc/salt/minion

        echo "master_port: 4506" >> /etc/salt/minion

        echo "backup_mode: minion" >> /etc/salt/minion

        echo "output: nested" >> /etc/salt/minion

        echo "acceptance_wait_time: 10" >> /etc/salt/minion

        echo "acceptance_wait_time_max: 0" >> /etc/salt/minion

        echo "random_reauth_delay: 60" >> /etc/salt/minion

        service salt-minion start

        service salt-minion status

    runstatus=`echo $?`

        if [ $runstatus == 0 ];then

        echo "salt-minion start sucessfully"

                exit 0

        else

        echo "salt-minion start fail"

                exit 0

        fi

fi