Linux Bulk copy data script

Source: Internet
Author: User

Recently wanted to get a bulk transfer copy deploy remote server script

Train of thought: 1. Establishing equivalence with remote clients

2. Copying data, or executing remote server commands

The automation equivalence script is as follows: If you install expect this package

================================================================

Server-side generation automatically generates 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 [email protected]$ip
Expect {
\ "*yes/no*\" {send \ "yes\r\"; Exp_continue}
\ "*password*\" {send \ "$password \r\"; Exp_continue}
\ "*password*\" {send \ "$password \r\";}
}
"
Done

Where the Ip.txt content format is as follows:

192.168.1.56:123456

===============================================================

Perform service-to-Client push commands

For h in $ (cat/script/ip.txt|cut-f1-d ":")
Do
SSH [email protected]$h "ls $dire"
Dire= "/tmp/test"
If [$?-eq 0];
Then
SSH [email protected]$h rm-rf "$dire"
Set Timeout 300
SSH [email protected]$h mkdir-p/tmp/test
Fi
SSH [email protected]$h Touch lgl.txt
Scp/root/centos-5.3-x86_64-bin-dvd.iso [email protected]:/Home
Set Timeout 300
Done

===============================================================

The final script is as follows:

[email protected] 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[email protected]$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[email protected]$h "LS $dire"
Dire= "/tmp/test"
If [$?-eq 0];
Then
Ssh[email protected]$h rm-rf "$dire"
Set Timeout 300
Ssh[email protected]$h mkdir-p/tmp/test
Fi
Ssh[email protected]$h Touch Lgl.txt
Scp/root/centos-5.3-x86_64-bin-dvd.iso[email protected]:/Home
Set Timeout 300
Done

This article is from the "Steven diligence in the Hippie:" blog, please be sure to keep this source http://steven2.blog.51cto.com/855881/1617514

Linux Bulk copy data script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.