03-30-2004
26,
0
Join Date: Mar 2004
Last Activity: 2 May 2004, 5:45 PM EDT
Posts: 26
Thanks Given: 0
Thanked 0 Times in 0 Posts
Help!!!!!!!!
As many of you on this forum already know, I have asked quite a few questions already that were probably elementary compared to your knowledge of Unix, but I have been searching through countless web pages, and consulting various books on the subject, and I am making progress to an extent.
I'm trying to write a shell script, that has been giving me an extreme headache, and I have it pretty much figured out...except for one certain part...a loop. Let me show you what I have so far so you can get a better idea of what I am trying to accomplish.
echo -n ' Login ID?: '
read loginID
echo -n ' UID?: '
Here's where I need a loop that will check to see if the UID is unique or not by checking in /etc/passwd.
I have a some idea of how to implement grep in a while loop, but I'm not sure of where to put what.
I came up with an if statement that I think will work, but then that wouldn't loop.
read UID
if [ " `grep $UID /etc/passwd ` " = 0 ] ; then
echo -n ' UID already exists - please re-enter a new UID '
UID = $<
That's probably not syntactically correct, but I think I'm in the ballpark somewhere.
The next lines are simple enough for me...
echo -n ' GID?: '
read GID
echo -n 'Comment?: '
read comment
echo -n ' Home Directory?: '
read homeDir
echo -n ' Startup Program?: '
read strtProg
Next I would just add the useradd command, but I couldn't find the proper option for the Login ID, so I am writing it as a ? in the below command:
useradd -? $loginID -u $UID -g $GID -c $comment -d $homeDir -s $strtProg
Now, when the script is finished, I should have an entry in the file passwd.user like:
johnd:x:204:300:John Doe:/home/johnd:/bin/bash
Could someone please help me with this? I am extremely confused with all the examples I've been reading online with the seds and awks, gawks, etc.
Thank you kindly
Meanwhile, I guess I will go throw on another pot of coffee...looks like I won't be sleeping tonight.