- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Scripting the creation of HP-UX user accounts
Operating System - HP-UX
1752815
Members
6442
Online
108789
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
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
- 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
- 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
- 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.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP