- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script to create user from a list of users
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
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
Community
Resources
Forums
Blogs
- 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
02-29-2004 11:30 PM
02-29-2004 11:30 PM
script to create user from a list of users
I'm trying to do a shell script to create users from a file that contain something like that:
username fullname
And is something like this:
...
for n in `cat users.txt`
do
useradd ...
passwd user
done;
But I have one problem inserting the password, how can use a default password, without interacting whit the sheel every time i create a user?
Any one has other ideas to improve the script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2004 11:42 PM
02-29-2004 11:42 PM
Re: script to create user from a list of users
Then write your user add script to insert this string into the password file. It's a bit of a hack and it can be dangerous if you don't test it carefully (i.e make sure you have a good copy of your passwd file).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2004 11:52 PM
02-29-2004 11:52 PM
Re: script to create user from a list of users
I am sorry not sure if i have understood your question. If you are looking at avoiding having to update passwd for every user, you can have that password as a variable.
But are you willing to assign the same initial passwd for all your users? If this is allowed then its fine.
Else you can look at generating a password and pass that into a variable each time you go through the loop of adding user.
regards
Mobeen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2004 11:53 PM
02-29-2004 11:53 PM
Re: script to create user from a list of users
Assuming your script is called adduser and the default password is defpass, you would run:
adduser defpass
where the passwd line in your file would be:
passwd user $1
Mark Syder (like the drink but spelt different)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2004 12:04 AM
03-01-2004 12:04 AM
Re: script to create user from a list of users
while read -r aa
do
useradd $aa
passwd $aa << EOF
defaultpass
defaultpass
EOF
done < /etc/passwd.copy
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2004 12:33 AM
03-01-2004 12:33 AM
Re: script to create user from a list of users
Like most backend commands, finding out how they work can be a challenge so I always start with something like:
/usr/sam/lbin/useradd.sam -abcxyz
/usr/sam/lbin/useradd.sam -abcxyz
Unrecognized Option 'a'
Usage: /usr/sam/lbin/useradd.sam [-p
group>[,
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2004 01:46 AM
03-01-2004 01:46 AM
Re: script to create user from a list of users
How can improve the script to insert a value from a variable in the password without interact to the shell?
I don't want this:
#sh cria_users
Changing password for u89874
New password:
Re-enter new password:
Passwd successfully changed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2004 02:02 AM
03-01-2004 02:02 AM
Re: script to create user from a list of users
I am not sure if your script is going to work. For ex., if you have your users.txt as
user1 FirstName1 LastName1
user2 FirstName2 LastName2
etc., then "for n in `cat users.txt` is not going to work as it will try to create users user1, FirstName1, LastName1, user2 etc.,
So, I would modify the file as
for USER in $(awk '{print $1}' users.txt)
do
useradd bla.bla.bla#your options
done
That will add the users. Make sure your users.txt is good and the login name appears always as the first word.
To set the passwords, I suggest you use Bill's approach of /usr/lib/makekey and usr/sam/lbin/useradd.sam. If you are going to keep one single default password for all these new users, then generate the encrypted of it by using /usr/lib/makekey. makekey supports only upto 8 chars of the password. If you want to set more than 8 chars, then you will need to write a small c program using bigcrypt. "makekey" accepts 10 chars with last two being random (called salt). So, to generate the encrypted string for the password "Test1234", I would do something like this
echo "Test1234xy"|/usr/lib/makekey
xyyB13z8Nr6jw
Then run usermod.sam command for each user
for USER in $(awk '{print $1}' users.txt)
do
usr/sam/lbin/useradd.sam -p xyyB13z8Nr6jw
/usr/bin/passwd -f $USER
done
passwd -f will expire the passwords so that when the user logs in, it will prompt him/her to change.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2004 02:08 AM
03-01-2004 02:08 AM
Re: script to create user from a list of users
Change the passwd line in my earlier posting to:
passwd user << endpasswd
$1
$1
endpasswd
You can use a shorter flag than endpasswd if you prefer.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2004 10:06 PM
03-01-2004 10:06 PM
Re: script to create user from a list of users
I've spent a month fooling around with Expect, when the answer was under my nose!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2004 03:55 AM
03-02-2004 03:55 AM
Re: script to create user from a list of users
Firstly there is no way of redirecting the default password's for all user through shell script even using "HERE" statement, because for a simple reason that unix always expects the password from the keyboard alone interactively.that indeed is a great security feature without which any intruder can go through all shell script and can get the knowledge about passwords or password setting patterns.
Bills method of setting the password could be followed, though I would be little cautious if I were you,because it is strongly advised against the practice of directly inputing the data into passwd file through a shell script unless it thoroughly checked against a dummy file ,just to be careful about the possible bug in ur script,
Instead I would suggest a option which can be used safely,
Try using 'passwd -d -f user' instead of 'passwd user' in ur for statement of ur shell script.Doing so will set a null password for all the new user u are creating(courtesy -d option) and also will force the users to assign a password the first time they log in (courtesy -f option)
Best of luck
senthil
i have attached a sample script