LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-22-2013, 02:59 PM   #1
manalisharmabe
Member
 
Registered: Dec 2010
Posts: 242

Rep: Reputation: 1
Cool Script copy multiple files from A B C to System Z over password less ssh.


hi all,

I need to write one script to copy multiple imp files
like
/etc/passwd
/etc/group
/etc/shadow
/etc/printers.conf
from system A, System B and system C to system Z
and I need to execute this script on System Z.
like if system is equal A copy 1 2 3 files to system Z into /A-files
if system is equal B copy 4 5 6 files to system z into /B-files
I have set password less ssh from and to A,B,C to Z and vice versa.

Could you please guide me as how to go about this..?

Thanks in Advance.
Manali.
 
Old 01-22-2013, 03:11 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Not to side-track you but you are re-inventing the wheel here. If your goal is configuration management, that is to say, making sure that system A has a certain /etc/passwd file while system B has another one, look at puppet or chef.

You can accomplish this via your method, you would have to create an ssh key for root and make sure it gets added to all the systems so that password less ssh can work via a script. Once that is done you can write a simple if then statement that checks md5 hashes on the files and copies them if they don't match.

I would strongly recommend taking a look at puppet, I have used it for years and am a huge puppet person. I have made a business case for implementing it at each company I have worked for and they usually go for it. The documentation is excellent as well and it should be pretty easy to install, and if you are going to manage less than 10 systems you can use the enterprise version for free which provides a nice GUI frontend.

http://docs.puppetlabs.com/puppet

Start here: http://docs.puppetlabs.com/learning/ They even have pre-made vm images you can use to get started!
 
Old 01-22-2013, 06:41 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Kustom42 may be correct, but another possibility, looking at the direction of the copies ie from A, B, C all to named dirs on Z suggests a backup scenario.
Normally Puppet is sending updates out, not pulling stuff back like that.
If this is a backup scenario, given passwordless logins setup, you'd just write a shell script with a loop and put it in cron.

You'll want these
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
http://www.adminschoice.com/crontab-quick-reference

In the long run you may want to setup a proper backup system; what would you do when one of those hosts dies, you'll need more than those few files?
 
Old 01-23-2013, 12:24 AM   #4
manalisharmabe
Member
 
Registered: Dec 2010
Posts: 242

Original Poster
Rep: Reputation: 1
Thanks chrism101 and Kustom42 for replies.
No we have our Backup happening through Netbackup daily. It is just to be more safer and easier side to get those important files back rather than calling tape and then doing restores.

can this following script be useful ?



Code:
case $(hostname -s) in
systemA)
scp -p /etc/passwd systemz:/usr/local/backup/A-Files/
scp -p /etc/group systemz:/usr/local/backup/A-Files/
;;
systemB)
scp -p /etc/passwd systemz:/usr/local/backup/B-Files/
scp -p /etc/group systemz:/usr/local/backup/B-Files/
;;
esac

thanks.
 
Old 01-23-2013, 03:02 AM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
scp using keypair authentication would be an easy method of achieving this.
 
Old 01-23-2013, 06:58 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
That code looks about right (but needs testing of course) if its a push scenario.
You could use a pull scenario from systemZ, so you'd only have one copy to maintain & more secure.

I'm still not convinced this is worth it though, unless you specifically expect ONLY those files to become corrupt.
Note that if you go down this road, you'll need the shadow file as well.


What specific problem do you hope to solve by doing this?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
After ssh-copy-id , still need to provide password bucz Linux - Networking 8 10-08-2019 06:36 AM
SSH : get password protection back after copy key jonaskellens Linux - Newbie 7 01-23-2013 08:25 AM
[SOLVED] copy multiple files to multiple directories Sanderson Linux - Newbie 15 01-22-2013 10:17 AM
[SOLVED] Bash script to extract multiple files with password musonio Linux - Software 8 03-12-2011 04:11 AM
Creating a script to move or copy files into multiple directories below the files matthes138 Linux - Newbie 5 08-25-2009 04:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration