Click to See Complete Forum and Search --> : useradd script help
lenny linux
12-03-2003, 02:46 AM
I have a useradd script that adds users, passwd, uid, gid, account disable, and some other tricks and trinkets. I want to add a function to look at the $LOGIN names when added and add a number so that users with the same login name will not cause a conflict.
Example: using the cut first 3 of lastname and cut first 2 of firstname
beth neely would be created and login as neebe
ben needles would be created and login as neebe but with a number after the login name.
neebe1 or 2
in my script would the following code
if [ "$LOGIN" = "$LOGIN" ]
then
[ "$LOGIN + 1" ]
fi
accept and increment the login names.
neebe
neebe1
JThundley
12-03-2003, 03:37 AM
if [ "$LOGIN" = "$LOGIN" ]
then
[ "$LOGIN + 1" ]
fi
I'm not exactly sure what you are trying to do, but I'm sure that $LOGIN = $LOGIN will always be true. Also you can't add a one to a string like that (you can in mython).
you might want to use `whoami` somewhere in there.
I don't even have a $LOGIN set anywhere. What does this variable hold?
Are you really adding that many users to your system?
lenny linux
12-03-2003, 12:51 PM
I want to test useradd for same login name so I can add users with same first 3 letters of last name and first 2 letters of first name with a number if they are the same when created.
A user: neebe can login as neebe with there password
Another user is created with the same 3 first letters in last name and first 2 letters in first name, which will match the other neebe.
So I want to create in my script a test if I have 2 lognames with the same user login to add a number to the logname of 1 or more lognames that duplicate when I create users from my useradd script.
I just need to figure out how, in my script I should code this to add a number after more neebe useradds automaticaly.
I want users: neebe, neebe1, neebe2 when created.
JThundley
12-03-2003, 01:02 PM
Just curious, do really need this script, or are you just trying to learn shell scripting or playing with the idea?
The reason I ask is because I have an idea of how it could work, but I don't want to write it for you if you're trying to learn. Also I'm failing the A+ class that I'm in typing this right now :( .
Each user will have a home in /home, right?
stiles
12-03-2003, 02:04 PM
I think the first thing you need to do is parse /etc/passwd for the username you are trying to create, something like this:
cut -d ":" -f "1" /etc/passwd | grep "$USER_NAME"
if you test the output of that and get nothing you can create the user as is, but if it has matches you need to cut the numbers after the generated username and do something with that. It should be pretty easy.
stiles
12-03-2003, 02:32 PM
Originally posted by lenny linux
userasdd script
I have this script already in use.. I think I have to use an expression such as
if [ "$LOGNAME" = "$LOGNAME" ]
then
[ "$LOGNAME((+1))" ]
fi
I want to compare created users to existing users who may have the same first 3 letters and first 2 letters of a login name. if they exist than add a numeric number to the end of the newly created user.
well I can't tell what you are doing. "$LOGNAME" = "$LOGNAME" is always going to be ture, so why even test that? Incrimenting a string can't be done like that, you could cut off the numbers that have been appended to the user name and test for the greatest value and then incriment that value (I'm sure that there is more that one way to do that no doubt).
lenny linux
12-03-2003, 03:18 PM
Stiles: I previously posted before seeing your reply.. it would make sense to parse the passwd file for the existance of the same user login name than add a numeric value to the new login name if it exist.
Thanks
GlennaclawZ
12-09-2003, 08:52 PM
I believe that if u look on the old useradd script that comes with linux it will show u how to do it because the original useradd script doesnt let u add them.