- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: scripting question
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
тАО10-11-2002 05:54 AM
тАО10-11-2002 05:54 AM
IF $user IN group
THEN
FI
Where group is on of the groups in /etc/group?
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2002 06:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2002 06:04 AM
тАО10-11-2002 06:04 AM
Re: scripting question
# groups -l skchan
will list all groups to which user "skchan" belongs to. Isn't that what you wanted ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2002 06:06 AM
тАО10-11-2002 06:06 AM
Re: scripting question
export A=` cat /etc/group | grep $user | wc -l `
if [ $A = 1 ]
then
command
exit
fi
2nd command
Manoj Srivastava
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2002 06:07 AM
тАО10-11-2002 06:07 AM
Re: scripting question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2002 06:07 AM
тАО10-11-2002 06:07 AM
Re: scripting question
man id for more information
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2002 06:11 AM
тАО10-11-2002 06:11 AM
Re: scripting question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2002 06:39 AM
тАО10-11-2002 06:39 AM
Re: scripting question
You will need to use "groups username" or "groups -g username" instead of "groups -l username" if you don't use /etc/logingroups.
If the user is not listed in /etc/group for his primary group (as specified in /etc/passwd), "groups -g" will not list the user's primary group. "groups" and "id -Gn" will list the user's primary group.
If you have su'ed to an account, "groups" without specifying the username will default to whom you logged in as, not the current username. "id -Gn" defaults to the current username.
Personally, I like:
id -Gn $user | grep groupname >/dev/null
if [ $? = 0 ]
then
echo is a member of the group
fi
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2002 06:53 AM
тАО10-11-2002 06:53 AM
Re: scripting question
I've tried the "id -nG username" command and don't get any results, even if I use a username that I can clearly see in /etc/group as belonging to a group.
The cat /etc/group works for me. I guess I was thinking too complicated to not think of something so simple!
Thank you all for helping me with my mental block!
Michele