inserting usr into /etc/passwd via script
ok I have an issue. I need to either locate a script that is similar to what I am needing or figure out a better way of doing what I need.
I have mutiple shops with AIX unix servers, using ksh with virtual terminals that connect. since these are on an internal network we have them connecting to the server as either usr01, usr02, etc. what I need to do is add 15 user's ranging from usr01-usr15 into /etc/passwd each usr is identical in such that each line contains Code:
usr01::0:0::/usr/tops:/bin/ksh I wrote a script where I was just adding these all to the /etc/passwd but now I have been tasked with adding them to these shops but with out any duplicates. is there any way to have a script check the file to see if the usr# exists and if so proceed to the next number and then input the usr#::0:0::/usr/tops:/bin/ksh into the file? any assistance or even a shove off teh correct cliff will help. Thanks in advance. |
You should just need to use grep to see if any lines match the username.
|
Editing /etc/passwd is the wrong way to do it. Are you even touching /etc/security/passwd?
Use useradd instead. Fill out its switches and write a script with 15 useradd lines (or a loop from 01 to 15). useradd will return an error when the user exists, solving your duplicate problem. Just make sure that your script doesn't quit on the first error. useradd will also PROPERLY add users to a system. |
Quote:
I cant edit the switchs on over 800 shops. I just need to be able to enter those lines into the /etc/password with out causing duplicates. I send the script out to all the shops via a SENDLIST.sh and it then runs the script on the system at the next cron job processing which is every 15 minutes on our systems. the usr01, usr02 are just the way teh workstation connects to the server. once it connect to the server it auto opens our menu driven software so there is no need for worry or concern of it not being the correct way or unsecure way. Quote:
so how would you recommend using grep to have the script check the file and see if there is an entery and if there isnt then to add one. |
So.. if
Quote:
Code:
useradd -s /bin/ksh -d /usr/tops user01 |
Quote:
Code:
awk '/^usr[0-9][0-9]*:/ { next } Without awk, you'll have to do it in two phases. First eliminate any old usr users via Code:
sed -e '/^usr[0-9][0-9]*:/ d' /etc/passwd Hope this helps, Nominal Animal |
Quote:
A script might look like this: Code:
for num in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 This loops through the possible combinations of usr01 through usr15, does a grep on /etc/passwd to see if the id already exists, and if not creates it, adding a user defined comment (like "virtual terminal id"), assigns the id to a group of your choice, and sets the login shell as ksh. ______ Dennis |
Thank you
Thank you to both Nominal Animal and DMcCunney. That looks like what I am needing thank you
|
All times are GMT -5. The time now is 05:15 PM. |