- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: shell script doubt in for loop
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
Discussions
Discussions
Forums
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
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
тАО05-19-2009 05:35 AM
тАО05-19-2009 05:35 AM
I want to create a shell script to find that is particular user available in what are the servers.
we are lot of hp-ux server. some users are created in some servers and not created in some servers.
so from being one hp-ux server i want to see this.
rlogin is enabled in all the servers.
and in rhosts file of the all the servers has the entry for connecting server (from which i am going to search the users.)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2009 05:47 AM
тАО05-19-2009 05:47 AM
Re: shell script doubt in for loop
if not, one way might be
read "username" from command line parm
File w/ list of "servers"
for servername in above list
remsh
details and implementation are left as an exercise.
there are other ways, and remsh / rlogin isn't secure.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2009 05:58 AM
тАО05-19-2009 05:58 AM
Re: shell script doubt in for loop
If nothing's been configured/started already, then don't start out using rlogin/remsh. With a little bit of pre-work, you can use secure shell/public key authentication to get the same results with greater security and flexibility.
Do a search in itrc for procedures on configuring ssh/pka. It's relatively simple.
Once that's done, you can then do something like the following:
#!/bin/ksh
User=$1
[[ ${#User} -eq 0 ]] && exit 1
for h in $(cat list-of-hosts-file)
do
l=$(ssh ${h} grep "^${User}:" /etc/passwd > 2>/dev/null)
printf "%-8s %s\n" ${h} "${l:=Not defined}"
done
Hope that helps.
Doug
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2009 06:05 AM
тАО05-19-2009 06:05 AM
SolutionOk, here's one way.
#!/usr/bin/sh
typeset USER=$1
while read HOST X
do
RESULT=$(rsh ${HOST} -n grep ^${USER}: /etc/passwd)
if [ -z "${RESULT}" ]; then
echo "${USER} missing on ${HOST}"
else
echo "${USER} exists on ${HOST}"
fi
done < /tmp/hosts
...
The '/tmp/hosts' file contains a hostname (one per line).
Now go examine the manpages for 'rsh' and note the use of the '-n' option. Notice that while I used a simple 'grep' I anchor what I want to match to the beginning of a line with the caret (^) symbol and specify the ":" to limit the match at the end of the string I want to be significant.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2009 09:38 AM
тАО05-19-2009 09:38 AM
Re: shell script doubt in for loop
Oops! Replace "rsh" with 'remsh' in my script. "rsh" = Restricted Shell. "remsh" stands for "remote shell".
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2009 11:21 AM
тАО05-19-2009 11:21 AM
Re: shell script doubt in for loop
Ex:
I am entering the following command directly in command prompt.
>for i in 10.250.0.2
>do
>ssh $i "grep john /etc/passwd
>done
So the above command is working fine for singel system
But i have lot of system.
So I created a file called "servers" and mentioned all the servers' ip address in that file.
Then i mentioned that file like
>for i in /root/servers
>do
>ssh $i "grep john /etc/passwd
>done
How to solve this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2009 11:28 AM
тАО05-19-2009 11:28 AM
Re: shell script doubt in for loop
> How to solve this.
If yuo are already using 'ssh' in lieu of 'remsh' then, very good.
Both Doug and I showed you how to use a file containing a list of servers. Read what has been posted.
Too, your 'grep' will match things you don't want to match! Again, _READ_ what I said about matching to the beginning of a line and only up to a colon (":")!
You already have the answer to your question.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2009 09:33 PM
тАО05-19-2009 09:33 PM
Re: shell script doubt in for loop
>for i in /root/servers
>do
>ssh $i "grep john /etc/passwd
>done
you have to do like this way
for i in `cat /root/servers`
do
ssh $i grep john /etc/passwd
done
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2009 11:26 PM
тАО05-19-2009 11:26 PM
Re: shell script doubt in for loop
check below link for shell,
http://docs.hp.com/en/B2355-90046/ch14s03.html
if helps,pls assign pont.
Rgds//
Taifur