Register
It is currently Sat Oct 25, 2014 3:10 pm

Gathering info from server farm


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Sun Dec 20, 2009 2:43 pm   

Joined: Sun Dec 20, 2009 2:09 pm
Posts: 3
Hi all,

I am trying to get a basic script to search for a string trough a log file and multiple servers...

scipt is very basic and goes like this:

#! /bin/bash

echo "Please enter Cust# to search for:"
read custsearch

for xus in 1 2 3 4 5 6 7;
do ssh www-$xus.my.domain.com; 'cd /path/to/log; grep $custsearch server.log > tmpsearch.txt'
scp user@www-$xus.my.domain.com:/path/to/log tmpsearch.txt $custsearch.$xus.log;
cat $custsearch.$xus* >> $custsearch.`date+"%m%d%Y"`.log;
done;

at this point i cant even get $xus recognized in the ssh command ????

i tried to declare an array

xus=('1' '2' '3' '4' '5' '6' '7');
for i in xus do ssh www-$xus.my.domain.com; 'cd /path/to/log; grep $custsearch server.log > tmpsearch.txt'
scp user@www-$xus.my.domain.com:/path/to/log tmpsearch.txt $custsearch.$xus.log;
cat $custsearch.$xus* >> $custsearch.`date+"%m%d%Y"`.log;
done;

but that script stop after it ssh'd and just sits there...


Top
 Profile  
 PostPosted: Sun Dec 20, 2009 3:28 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
are your servers named
http://www.1.my.domain.com
http://www.2.my.domain.com
and so on?


Top
 Profile  
 PostPosted: Sun Dec 20, 2009 3:39 pm   

Joined: Sun Dec 20, 2009 2:09 pm
Posts: 3
yes they are


Top
 Profile  
 PostPosted: Sun Dec 20, 2009 4:13 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
the first problem you have is the semicolon after the ssh command.
Code:
for xus in {1..7}; do
ssh www-${xus}.my.domain.com "grep \"$custsearch\" /path/to/log/server.log" > ${custsearch}.${xus}.txt
cat ${custsearch}.${xus}.txt >> ${custsearch}.$(date +'%Y%m%d').log;
done;
is it ok?
curly braces around variables might not be necessary, try with and without.


Top
 Profile  
 PostPosted: Sun Dec 20, 2009 4:49 pm   

Joined: Sun Dec 20, 2009 2:09 pm
Posts: 3
it works...
thanks a million


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP