Well, the one-liner that I wrote before it's pretty close to what you want.
I shall explain it in more detail:
for server in [ mumbai bangalore chennai delhi hyderabad other-hostnames ]; do echo $server; ssh $server zcat /path/to/voter.gz | grep -l "keyword"; done
The
for server in [ mumbai bangalore chennai delhi hyderabad other-hostnames ]
executes the command following the reserved where "do" for all the hostnames in the list between square brackets ().
The
echo $server
just prints out the hostname in stdout for a more clear output trace.
The
ssh $server zcat /path/to/voter.gz | grep -l "keyword"
does this: connect to $server defined by the for loop and do a zcat on the file. This prints to stdout all the contents of the compressed files. Immediately after that pipe (|) the output to a grep command that will search for the keyword. The "-l" argument will show only the name of the file if the keyword is found. If you omit that, you'll get the actual text line of the keyword.
If the user in your workstation is not the same as in the servers you should replace ssh $server with ssh user-name@$server, where user-name is the login in the servers.
On the other hand, if you have different logins for your servers, I suggest replacing [ mumbai bangalore chennai delhi hyderabad other-hostnames ] with [ user@mumbai user@bangalore user@chennai user@delhi user@hyderabad user@other-hostnames ]. Each of the user for each of the servers could be completely different. Example: root@mumbai prasad@chennai user2345@delhi, etc.
Using "for" you'll be searching through the servers one at a time. To bypass this, you could execute all the ssh commands in background logging the output to files and then look for the results in those files.
for server in [ mumbai bangalore chennai delhi hyderabad other-hostnames ]; do echo $server; ssh $server zcat /path/to/voter.gz | grep -l "keyword" & done
Note the ampersand replacing the last semicolon.
You can safely put this on a script that would look something like this:
#!/bin/bash
for server in [ mumbai bangalore chennai delhi hyderabad other-hostnames ]; do echo $server; ssh $server zcat /path/to/voter.gz | grep -l "$1" & done
and then, when you invoke the script you should do it like this:
./your-script.sh keyword
I do realize something else: if you have multiple compressed files to search for the faster way would be to use a find command and then execute the grep. The line should be something like this:
for server in [ mumbai bangalore chennai delhi hyderabad other-hostnames ]; do echo $server; ssh $server "find /path/to/file/*.gz -exec zcat {} \; | grep -l "$1"" & done
I actually don't have a *nix machine to test this out. I'm sure some of the double quotes could be wrong, so you should experiment yourself.
If you have any question feel free to ask but take in consideration the latter (you have to try it yourself!).
Good luck,
Leandro.
---------- Post updated at 11:29 AM ---------- Previous update was at 11:11 AM ----------
Yep! If he has that command installed in all servers, it'll do just fine. In fact, it would be recommended instead of "zcat | grep".