- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Searching a word pattern on many servers from a pa...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2009 02:50 PM
03-25-2009 02:50 PM
I am trying to search a particular word starting from current directory
as below:
$find . -type f -exec grep -i "shiv" /dev/null {} \;
The above command works fine on a single server.
Now i want to search a particular word pattern starting with some directory and traversing its sub-directories
on number of servers. My userid is ssh enabled to all the required servers.
Can someone tell how to do this ?
Thanks,
Shiv
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2009 03:25 PM
03-25-2009 03:25 PM
SolutionYou can do:
for HOST in server1 server2 server3
do
ssh ${HOST} 'find /path -type f -exec grep -i "shiv" /dev/null {} +'
done
...or if the file "HOSTLIST" has the server names (one per line):
while read HOST X
do
ssh ${HOST} 'find /path -type f -exec grep -i "shiv" /dev/null {} +'
done < HOSTLIST
...
Notice that I used the "+' terminator which optimizes things by bundling many arguments (Here, file names) into a list and spawning one 'grep' process to handle them.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2009 04:26 PM
03-25-2009 04:26 PM
Re: Searching a word pattern on many servers from a particular server
The only change I would make would be to add some echo statements to Mr. Ferguson's scripts so that you know which server you are running on and to provide some spacing between results.
for HOST in server1 server2 server3
do
echo ${HOST}
ssh ${HOST} 'find /path -type f -exec grep -i "shiv" /dev/null {} +'
echo ""
done
...or if the file "HOSTLIST" has the server names (one per line):
while read HOST X
do
echo ${HOST}
ssh ${HOST} 'find /path -type f -exec grep -i "shiv" /dev/null {} +'
echo ""
done < HOSTLIST
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2009 04:27 PM
03-25-2009 04:27 PM
Re: Searching a word pattern on many servers from a particular server
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2009 04:37 PM
03-25-2009 04:37 PM
Re: Searching a word pattern on many servers from a particular server
Yes, my friend Patrick makes a very good suggestion! Most certainly it would be nice to add the hostname to the output!
/* no points for this comment */
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2009 04:45 PM
03-25-2009 04:45 PM
Re: Searching a word pattern on many servers from a particular server
for HOST in $(< HOSTLIST); do
ssh ${HOST} 'find /path -type f -exec grep -i "shiv" /dev/null {} +' > $HOST.out &
done
wait
for HOST in $(< HOSTLIST); do
echo "Searching $HOST:"
cat $HOST.out
done