I have many servers like sdeuu1, sdeuu2, sdeuu3,.. etc.
I want to run a query on each one of them and the query is :
grep -i 'SponsoredLinksIFrame.jsp' /home/nextag/httpd_logs/access_log.1360* |
grep -ic 'nextag.co.uk'
this query is returning perfect results when ran on separate servers.
Now i have one server named sdalp1 through which i can ssh to sdeuu1, 2, 3 etc.. and go to that server to run the query. Now instead of doing that i want to run the query from sdalp1 for all the sdeuu servers in one go and i tried the following command and a few other versions of it:
for i in sdeuu1 sdeuu2 sdeuu3 sdeuu4 sdeuu5 \
sdeuu6 sdeuu7 sdeuu8 sdeuu9 sdeuu10 \
sdeuu11 sdeuu12 sdeuu13 sdeuu14 sdeuu15 \
sdeuu16 sdeuu17 sdeuu18; do
grep -i 'SponsoredLinksIFrame.jsp' /home/nextag/httpd_logs/access_log.1360* |
grep -ic 'nextag.co.uk'"
echo $i
done
But this command is returning an error for all servers as follows:
-bash: grep -i 'SponsoredLinksIFrame.jsp' /home/nextag/httpd_logs/access_log.1360* | grep -ic 'nextag.co.uk': No such file or directory
What is the problem here, i am not getting if this is an issue with permissions?
Note that I added
ssh $i
to the start of the command inside the loop.I also added a backslash (
\
) to the pipe symbol (|
), so that the second grep happens on each individual server for efficiency. And then I also needed a backslash at the end of that line to indicate a continuation line, since the escaped pipe symbol no longer does it. When you type this in, make sure you don't put any spaces after that last backslash.If that's confusing, you can also do it with everything on one line:
If you haven't already, you can set up passwordless ssh login so that you don't have to type a password in for each server.