LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-24-2012, 10:03 AM   #1
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Post automate scp xfer over multiple hosts


I am trying to automate scp'ing the same file from multiple hosts.

I have most of it, but I need help, of course...
Here's the partial script:
Code:
CONF=/home/jj/.ssh/c9
SOURCE=$(sed '/^#/d' $CONF/*.hosts)
SECDIR=/home/jj/Documents/cirrhus9/Forensics
c9GROUPS=$(ls -1 $CONF/*.hosts | cut -c 18- | cut -d. -f1)

echo -n "/path/to/remote/file...? "
read MYFILE

echo "$SOURCE" | while read line 
do 
    c9IP=$(echo "$line" | cut -d@ -f2 | sed -e 's/"//') 
    c9KEY=$(echo "$line" | awk '{print $4}')
echo "scp -i $c9KEY root@$c9IP:$MYFILE $SECDIR/$c9IP/$(date '+%m-%d-%Y')" 
done
Code:
echo "scp -i $c9KEY root@$c9IP:$MYFILE $SECDIR/$c9IP/$(date '+%m-%d-%Y')"
would be replaced with
Code:
scp -i $c9KEY root@$c9IP:$MYFILE $SECDIR/$c9IP/$(date '+%m-%d-%Y')
as far as I can tell.

the CONF directory has these entries that I hope to use as a $c9GROUP variable in my script...
Code:
ls -1 /home/jj/.ssh/c9/*hosts
/home/jj/.ssh/c9/c9.hosts
/home/jj/.ssh/c9/donorschoose.hosts
/home/jj/.ssh/c9/ftb.hosts
/home/jj/.ssh/c9/rightservers.hosts
/home/jj/.ssh/c9/zoozooweb.hosts
and a sample .hosts file has this format (these are my sourced alias files)
Code:
alias zzgrid="ssh -qi /home/jj/.ssh/c9/c9devgid_rsa root@123.456.246.227"
alias zzftp="ssh -i /home/jj/.ssh/c9/moose_rsa root@123.456.246.241"
What I hope to achieve is script.sh <group> and a "read MYFILE" for the remote file for a single group.

I imagine it would go like so:
1. "script.sh" would echo the groups and proper 'usage' (script group /path/to/remote/file)
2. "script.sh groupname" would grab $MYFILE from a single group of said hosts, after reading MYFILE

I am sure there are many ways to skin this particular cat and I look forward to being amazed by some creative alternatives.

Thank you for your time.

Last edited by Habitual; 09-24-2012 at 10:04 AM.
 
Old 09-24-2012, 10:53 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Not an answer but wheel reinvention-wise did you know there's tools dealing with ^whatever.on.*multiple hosts like ClusterSSH, Dsh, Fanout / Fanterm, Tentakel, Shocto, SwitchTower, MUC (Massively Useful Cluster), Parallel SSH and RGANG?

Last edited by unSpawn; 09-24-2012 at 10:55 AM. Reason: //More *is* more
 
Old 09-24-2012, 11:04 AM   #3
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 647

Rep: Reputation: 189Reputation: 189
Just did a quick Google search for "scp multicast" and found this page on ServerFault. Maybe the last comment is the most easier to setup.
 
Old 09-25-2012, 01:01 PM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374

Original Poster
Blog Entries: 37

Rep: Reputation: Disabled
Thanks guys, but I prefer to "roll-my-own".
I installed ClusterSSH but didn't do much else with it. Should my script die a horrible death, or I simply can't get it the way that I'd like, I will have to give ClusterSSH a "go".

I am not sure how using native tools to get 'er done gets lumped into a "re-invent the wheel" category, but moving forward...

I prefer the challenges of scripted homegrown solutions.

So the script coding continues. I usually try to follow code examples I find on my Slackware box, like /usr/sbin/slackpkg, and /etc/rc.d/rc.* etc.

Have a Great Day!
 
  


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
Bash quesion - scp on multiple hosts to multiple directories in each one mierea.ciprian Programming 2 06-22-2012 12:27 PM
scp file to multiple hosts with expect loadedmind Programming 4 04-11-2011 09:28 PM
need to automate xfer of files from linux to windows rsmccain Linux - General 2 01-11-2007 01:27 PM
LXer: Speaking Unix, Part 6: Automate, automate, automate! LXer Syndicated Linux News 0 01-04-2007 09:54 AM
scp between 2 hosts from a 3rd host noir911 Linux - Networking 3 05-12-2006 05:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:23 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