Creating a group of users with script

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
Operating Systems HP-UX Creating a group of users with script
# 1  
Creating a group of users with script


I have a file with usernames, and the comment section, e.g :

donny:Donny Lee Feo Yan; Umobile Consultant
ebfhiil:Gaurav Mehra, Ericsson GNOC
egi19762:"ANISH ANTONY, MO 2nd LA, 31052016"
egi20330:"Gautam Harinarayanan, MO 2nd LA, 31052016"
egi20354:"ASHIM MALGOPE, MO 2nd LA, 31052016"
egi21634:"TIJENDRA DEVERA, MO 2nd LA, 31052016"
egi23959:"AMIT KUMAR, MO 2nd LA, 31052016"
egi34632:"KHUSHBOO BHATIA, MO 2nd LA, 31052016"
egi35873:"KRATI VASHISHTHA, MO 2nd LA, 31052016"
egi39015:"JASPREET SINGH, MO 2nd LA, 31052016"
egi39554:"SHIVANG NAYYAR, MO 2nd LA, 31052016"
egi42048:"POOJA SHARMA, MO 2nd LA, 31052016"
emansab:Manpreet singh Sabharwal MO GNOC Engineer
emoaigin:Aigini Navaneethan, Ericsson Sysadmin
emoazizu:Azizul Redzuan, Ericsson Sysadmin, 27042017
emofosee:Foo See See, Ericsson BA
emokchee:Ho Kok Chee, Ericsson MO
emomahat:Muhammad Mahathir Ismail, Ericsson Solution Architect/BA, 04042017
emovince:Vincent Wong, Ericsson Sysadmin, 07102015
etigers:Tiger Tool Monitoring User
gnocfo:GNOC common id, 12082015, Ashutosh Srivastava
hannkeat:Tan Hann Keat, Senior Engineer
lhs:Read only access for LHS support
master: MasterSAM normal ID, 22082017
msadmin:Master Security Administrator
pmuser:Automation Team user to collect KPI data, Tanuj Sood

I need to add these users into a server. Is it possible to use a script to create the users, together with the comment ?

From the commandline to add one user, the command will be :

useradd -m user -c "comment"

How do I do the same, for multiple users above, using script(automation)?
# 2  
Yes, it is possible.

The simplest way, I would say, is to use a while loop with a read, setting the field separator (IFS) to : to get each field from the file, and inside the loop run the useradd command.
This User Gave Thanks to Scott For This Post:
# 3  
Different approach:
sed 's/^/echo useradd -m /; s/;/,/; s/:/ -c \\"/; s/$/\\"/' file

redirect into a file and run / source that, or pipe the result into a shell. Remove the echo if happy with the proposal. Unfortunately, that sole ; in the comment will spoil the shell input and thus must be removed.
This User Gave Thanks to RudiC For This Post:
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #865
Difficulty: Easy
The original idea of a member badging system at was first proposed by Ravinder Singh in 2018.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script for creating multiple users with password

for UserName in `cat users` ; do useradd -d /u02 -s /usr/libexec/openssh/sftp-server -G ftp-users $UserName ; PassWord=$( echo $( tr '' '' <<< ${UserName:0:1} )${UserName:1} ) ; echo "$PassWord@123" | passwd $UserName --stdin ; done can some one explain what the bold text do Please use... (5 Replies)
Discussion started by: James0806
5 Replies

2. Red Hat

Script for Creating more users like 50 in one server

Hi friends could you please share me the script to create more users in one server except newusers, is there any option to change secondary group and how to print passwd and changing the age all these things how can i edit in newsers.. please help me (0 Replies)
Discussion started by: indiankrish
0 Replies

3. Shell Programming and Scripting

Writing a script on creating and comparing users

Hello Everybody i am a newbie to the bash scripting.please can someone help me out here.i want to write a script on creating 10 users with passwords and comparing the users to the ones in /etc/passwd i gonna use arrays in creating the 10 users or what?and again, how do i compare both... (1 Reply)
Discussion started by: bruno_brunt
1 Replies

4. Shell Programming and Scripting

Script to add new users to a group on multiple servers using SSH

Hi Experts, I am new to scripting. We have around 400 Linux servers in our environment. I want to add a new user to a perticular group on all the servers using SSH. Requirements: 1) Need to take the server names from a text file. 2) Login into each server and check whether perticular... (1 Reply)
Discussion started by: Satya1983
1 Replies

5. UNIX for Dummies Questions & Answers

Script for creating users

Hi, I wants to create the users for multiple machine from single main server using the shell script ,can you please help me on this.... (2 Replies)
Discussion started by: Rahulne25
2 Replies

6. Shell Programming and Scripting

Script in bash wchich creating a new users...

Hi, I am a new on this forum but i like :) I need a script in bash which will be crating a new user with folder for websites. For example: I will run this program and he creating a new user(with my name) and folder whcich name like user and if i will localho/~user in browser, she show me files from... (1 Reply)
Discussion started by: puclavv
1 Replies

7. BSD

Creating an array out of users: shell script

I want to create a shell script for a menu selection consisting of users defined on the machine. To an administrator having the privileges, the selection menu will look as follows: Select the user you want to define the variables for: 1) my-username-1 2) my-username-2 etc Then there would be a... (7 Replies)
Discussion started by: figaro
7 Replies

8. Shell Programming and Scripting

Help with shell script - creating users

echo -e "Enter in a username : \c" read username grep "^$username:" /etc/passwdWhat I'm trying to do is take in a username from my script and I need to be able to check if that username already exists. If it does the script should display a message saying that the user already exists and exit. ... (2 Replies)
Discussion started by: shadowcat
2 Replies

9. Shell Programming and Scripting

Script to list primary group of users

Dear All I am facing a problem with my script. I have to found the primary group of users . So first I selected all the groups and users register from a specific user : ONE Then I am making a file with all groups attached to the user : ONE Then I am making a file with all... (8 Replies)
Discussion started by: Aswex
8 Replies

10. AIX

script for finding all the users with GID 0 ( admin group )

Hi Friends, I am trying to write a script for finding all the users with the GID 0 i.e. Admin users. can you please help me on this. (1 Reply)
Discussion started by: anoopraok
1 Replies

Featured Tech Videos