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.