LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-11-2004, 08:25 AM   #1
pheasand
LQ Newbie
 
Registered: Sep 2004
Posts: 7

Rep: Reputation: 0
Bash Script- Finding/Generating unique UserIDs


Hello everyone,

I am working on a bash script for a UNIX class that I am taking and I need to create a program that adds and deletes users from a passwd file. My problem is generating a Unique User ID for the case when a user is added to the system. I am wondering if there is a command that will parse passwd and auto-generate UUIDs or else a basic loop that I can use to find/generate a unique user ID for the passwd file. My (un-elegant) solution is as follows:

Take the UID from the last user in passwd file
Increment UID by 1
LOOP: (most likely a while)
grep passwd file for UID
if grep is sucessful
then increment UID by 1 again and loop
else we have a unique ID
END LOOP


Thanks for your help,

D.
 
Old 12-11-2004, 09:03 AM   #2
ranger_nemo
Senior Member
 
Registered: Feb 2003
Location: N'rn WI -- USA
Distribution: Kubuntu 8.04, ClarkConnect 4
Posts: 1,142

Rep: Reputation: 47
Re: Bash Script- Finding/Generating unique UserIDs

Quote:
I am working on a bash script for a UNIX class....
From the Rules page... "Do not expect LQ members to do your homework...."

That being said, I will suggest the following line that you might use...

awk -F: '{print $3}' /etc/passwd

It uses the program awk to split the file /etc/passwd into columns, using colons as the deliminator, and prints out the third column from each row.
 
Old 12-11-2004, 09:44 AM   #3
pheasand
LQ Newbie
 
Registered: Sep 2004
Posts: 7

Original Poster
Rep: Reputation: 0
Re: Re: Bash Script- Finding/Generating unique UserIDs

Quote:
Originally posted by ranger_nemo
From the Rules page... "Do not expect LQ members to do your homework...."
I don't believe that I am asking anyone to DO my homework for me. I explained a problem, posted MY solution to it, and then asked if there was a more elegant solution than mine. I was not asking people to completely write the script or even asking for someone to write a section of it for me. Instead I was trying to "bum" lines of code from my script in order to make it faster and better. I believe that rule is aimed towards those who expect others to do their work for them.


-D.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
finding empty directories with bash Iriel Solaris / OpenSolaris 10 02-18-2016 03:59 AM
Generating iteratable arrays in bash d00bid00b Programming 4 08-15-2005 04:54 PM
Need help with finding path in bash script ylikone Linux - Software 1 08-02-2005 10:47 AM
Generating A Script gizza23 Linux - Software 7 07-24-2005 07:33 PM
bash scripting: problem with generating filenames mad_juno Programming 2 07-22-2005 10:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration