Skip to ContentSkip to Footer
Start of content
- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - HP-UX
- >
- General
- >
- Scripting the creation of HP-UX user accounts
General
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
Topic Options
- 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
- Email to a Friend
- Report Inappropriate Content
12-11-2009 05:26 AM
12-11-2009 05:26 AM
Scripting the creation of HP-UX user accounts
Hi, not sure if any one can help, we have a lagacy application where all database authentication is controlled from the /etc/passwd.
We have UID and GIG ranges for each department. I am trying to write a script the looks and creates the next available UID in the assigned range.
I believe I will need somthing like
UID must must greater than "UIDLOW" and less than "UIDHIGH" and create UID one greater than the lowest UID in the range.
Any help would be most appreciated
Regards
John
We have UID and GIG ranges for each department. I am trying to write a script the looks and creates the next available UID in the assigned range.
I believe I will need somthing like
UID must must greater than "UIDLOW" and less than "UIDHIGH" and create UID one greater than the lowest UID in the range.
Any help would be most appreciated
Regards
John
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
12-11-2009 06:33 AM
12-11-2009 06:33 AM
Re: Scripting the creation of HP-UX user accounts
You'll need a shell script/function that iterates over the assigned range from UIDLOW to UIDHIGH and stops when it finds a free UID.
How about something like this:
#!/bin/sh
iterateUID () {
UIDLOW="$1"
UIDHIGH="$2"
ASSIGN_UID=none
CURR_UID="$UIDLOW"
while [ "$CURR_UID" -lt "$UIDHIGH" ]; do
grep -q "^[^:]*:[^:]*:$CURR_UID:" /etc/passwd
if [ $? = 0 ]; then
# UID is in use
CURR_UID=$( expr "$CURR_UID" + 1 )
continue
else
# found an UID
ASSIGN_UID="$CURR_UID"
break
fi
done
if [ "$ASSIGN_UID" = "none" ]; then
# could not find an UID
echo "ERROR: could not find a free UID. Range full?" >&2
echo "none"
return 1
fi
echo "$ASSIGN_UID"
return 0
}
If the function manages to find a suitable UID, it outputs it to stdout. If no free UID was found, it outputs an error message to stderr, sends the string "none" to stdout and returns with an error code.
After defining this function near the beginning of your script, you can use it like this:
# to find an UID between 100 and 200
USER_UID=$( iterateUID 100 200 )
if [ $? -gt 0 ]; then
# things to do if no UID found
fi
There are probably other, more resource-saving ways to do this.
For GIDs, change the variable names as appropriate and the "grep" line to:
grep -q "^[^:]*:[^:]*:$CURR_GID:" /etc/group
MK
How about something like this:
#!/bin/sh
iterateUID () {
UIDLOW="$1"
UIDHIGH="$2"
ASSIGN_UID=none
CURR_UID="$UIDLOW"
while [ "$CURR_UID" -lt "$UIDHIGH" ]; do
grep -q "^[^:]*:[^:]*:$CURR_UID:" /etc/passwd
if [ $? = 0 ]; then
# UID is in use
CURR_UID=$( expr "$CURR_UID" + 1 )
continue
else
# found an UID
ASSIGN_UID="$CURR_UID"
break
fi
done
if [ "$ASSIGN_UID" = "none" ]; then
# could not find an UID
echo "ERROR: could not find a free UID. Range full?" >&2
echo "none"
return 1
fi
echo "$ASSIGN_UID"
return 0
}
If the function manages to find a suitable UID, it outputs it to stdout. If no free UID was found, it outputs an error message to stderr, sends the string "none" to stdout and returns with an error code.
After defining this function near the beginning of your script, you can use it like this:
# to find an UID between 100 and 200
USER_UID=$( iterateUID 100 200 )
if [ $? -gt 0 ]; then
# things to do if no UID found
fi
There are probably other, more resource-saving ways to do this.
For GIDs, change the variable names as appropriate and the "grep" line to:
grep -q "^[^:]*:[^:]*:$CURR_GID:" /etc/group
MK
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
12-22-2009 06:24 AM
12-22-2009 06:24 AM
Re: Scripting the creation of HP-UX user accounts
Excellent feedback
thanks again
thanks again
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
End of content
United States
Hewlett Packard Enterprise International
Communities
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP