Linux batch copy data script

Source: Internet
Author: User

Linux batch copy data script

Recently, I want to get a Linux-based Batch Transfer copy deployment remote server script
Concept: 1. establish equivalence with remote clients
2. Copy data or execute remote server commands
The automated equivalence script is as follows:
========================================================== ======================================
The server generates an rsa key automatically.
#! /Usr/bin/CT
Rm-rf root/. ssh/known_hosts
CT-c"
Spawn ssh-keygen-t rsa
CT {
\ "* 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 ":")
CT-c"
Spawn ssh-copy-id-I/root/. ssh/id_rsa.pub root @ $ ip
CT {
\ "* Yes/no * \" {send \ "yes \ r \"; exp_continue}
\ "* Password * \" {send \ "$ password \ r \"; exp_continue}
\ "* Password * \" {send \ "$ password \ r \";}
}
"
Done
The content format of ip.txt is as follows:
192.168.1.56: 123456
 
 
========================================================== ======================================
Execute the push command from the server to the client
 
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
 
========================================================== ======================================
The script is as follows:
 
 
[Root @ lgl script] # cat ssh. sh
#! /Usr/bin/CT
Rm-rf root/. ssh/known_hosts
CT-c"
Spawn ssh-keygen-t rsa
CT {
\ "* 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 ":")
CT-c"
Spawn ssh-copy-id-I/root/. ssh/id_rsa.pub root @ $ ip
CT {
\ "* 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

This article permanently updates the link address:

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.