|
Recently I tried to get hold of a copy of the Linux transmission Batch deploy remote server script.
Ideas:
1. establish equivalence with the remote client
2. Copy the data, or perform remote server commands
Automation equivalence script as follows: the premise is expect this package to install
================================================== ==============
The server generates automatically generate rsa key
#! / Usr / bin / expect
rm -rf root / .ssh / known_hosts
expect -c "
spawn ssh-keygen -t rsa
expect {
\ "* Id_rsa * \" {send \ r; exp_continue}
\ "* Passphrase * \" {send \ r; exp_continue}
\ "* Again * \" {send \ r; exp_continue}
}
================================================== =============
Copy the generated key to the remote server
for p in $ (cat /script/ip.txt)
do
ip = $ (echo "$ p" | cut -f1 -d ":")
password = $ (echo "$ p" | cut -f2 -d ":")
expect -c "
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root @ $ ip
expect {
\ "* Yes / no * \" {send \ "yes \ r \"; exp_continue}
\ "* Password * \" {send \ "$ password \ r \"; exp_continue}
\ "* Password * \" {send \ "$ password \ r \";}
}
"
done
Wherein ip.txt content format is as follows:
192.168.1.56:123456
===============================================================
Execution services to client push command
for h in $ (cat /script/ip.txt|cut -f1 -d ":")
do
ssh root @ $ h "ls $ dire"
dire = "/ tmp / test"
if [$ -eq 0?];
then
ssh root @ $ h rm -rf "$ dire"
set timeout 300
ssh root @ $ h mkdir -p / tmp / test
fi
ssh root @ $ h touch lgl.txt
scp /root/CentOS-5.3-x86_64-bin-DVD.iso root@192.168.1.56: / home
set timeout 300
done
===============================================================
Finally, the script is as follows:
[Root @ lgl script] # cat ssh.sh
#! / Usr / bin / expect
rm -rf root / .ssh / known_hosts
expect -c "
spawn ssh-keygen -t rsa
expect {
\ "* Id_rsa * \" {send \ r; exp_continue}
\ "* Passphrase * \" {send \ r; exp_continue}
\ "* Again * \" {send \ r; exp_continue}
}
"
for p in $ (cat /script/ip.txt)
do
ip = $ (echo "$ p" | cut -f1 -d ":")
password = $ (echo "$ p" | cut -f2 -d ":")
expect -c "
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root @ $ ip
expect {
\ "* Yes / no * \" {send \ "yes \ r \"; exp_continue}
\ "* Password * \" {send \ "$ password \ r \"; exp_continue}
\ "* Password * \" {send \ "$ password \ r \";}
}
"
done
for h in $ (cat /script/ip.txt|cut -f1 -d ":")
do
ssh root @ $ h "ls $ dire"
dire = "/ tmp / test"
if [$ -eq 0?];
then
ssh root @ $ h rm -rf "$ dire"
set timeout 300
ssh root @ $ h mkdir -p / tmp / test
fi
ssh root @ $ h touch lgl.txt
scp /root/CentOS-5.3-x86_64-bin-DVD.iso root@192.168.1.56: / home
set timeout 300
done |
|
|
|