#!/bin/bash
for i in $(cat ./host.txt)
do
echo $i > ./tmp.txt
HOSTNAME=$(cut -d ':' -f1 ./tmp.txt)
IP=$(cut -d ':' -f2 ./tmp.txt)
PASS=$(cut -d ':' -f3 ./tmp.txt)
/usr/bin/expect <<-EOF
spawn ssh $IP
expect {
"yse/no" { send "yse\r";exp_continue }
"password" { send "$PASS\r" }
}
expect "*#"
send "cd /etc/yum.repos.d/ && rm -rf *.repo\r"
expect "*#"
send "wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo\r"
expect "*#"
send "wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo\r"
expect "*#"
set timeout 300
send "yum -y install salt-minion\r"
expect "*#"
send "exit\r"
interact
expect eof
EOF
sleep 30 /usr/bin/expect <<-EOF
spawn ssh $IP
expect {
"yse/no" { send "yse\r";exp_continue }
"password" { send "$PASS\r" }
}
expect "*#"
send "sed -i 's/#master: salt/master: 172.16.50.30/g' /etc/salt/minion\r"
expect "*#"
send "sed -i 's/#id:/id: $HOSTNAME/g' /etc/salt/minion\r"
expect "*#"
send "/etc/init.d/salt-minion restart\r"
expect "*#"
send "exit\r"
interact
expect eof
EOF
done
[root@centos- shell]# cat host.txt
lnmp:192.168.1.50:password
[root@centos- shell]#
[root@centos- shell]# cat salt.sh
#!/bin/bash for i in $(cat ./host.txt) do
echo $i >./tmp.txt
host_name=$(cut -d : -f1 ./tmp.txt)
ip=$(cut -d : -f2 ./tmp.txt)
pass=$(cut -d : -f3 ./tmp.txt) echo $host_name echo "$ip" echo "$pass" done
[root@centos- shell]# cat salt2.sh
#!/bin/bash for i in $(cat ./host.txt) do
host_name=`echo $i | awk -F : '{print $1}'`
ip=`echo $i | awk -F : '{print $2}'`
pass=`echo $i | awk -F : '{print $3}'` echo $host_name echo "$ip" echo "$pass" done
[root@centos- shell]#