Sponsored Content
Top Forums UNIX for Dummies Questions & Answers About adding users from a text file using bash Post 302954487 by ref012 on Tuesday 8th of September 2015 12:12:34 PM
Old 09-08-2015
Debian About adding users from a text file using bash

hello,

I try to add users from a text file with this form:

username:groupename:homedir


first i extract data which is separated by ":"
then i use useradd to add users/groups.

but,,, my code doesn't works :


Code:
#!/bin/bash

echo "give me a text file: "
read dir


# control if the file is valid
if [ -f $dir ]
then
       for user_dets in $(dir)      #loop and extract data
       do
                    user= echo "$user_dets" | awk -F\: '{print $1}'
                    group= echo "$user_dets" | awk -F\: '{print $2}'
                     home= echo "$user_dets" | awk -F\: '{print $3}'
                 
                     useradd -g "$group" -d "$home"  $user
 
        done
else
        echo "file is not valid"
fi

I found this code which probably do the same as awk 'also doesn't works':

Code:
user = $(echo $ligne | cut -d':' -f1)

Can someone help me please?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

adding text to a file between lines

Suppose content of my first file: first line second line third line How can i insert text between "first line" & "second Iline" Any help?????/ (7 Replies)
Discussion started by: bishweshwar
7 Replies

2. Shell Programming and Scripting

Adding specific text and spaces to each line in a text file

Hi, I wanted to add specific text to each row in a text file containing three rows. Example: 0 8 7 6 5 5 7 8 9 0 7 9 7 8 9 0 1 2 And I want to add a 21 at the beginning of the first row, and blank spaces at the beginning of the second two rows. To get this: 21 0 8 7 6 5 5 7 8... (4 Replies)
Discussion started by: hertingm
4 Replies

3. Shell Programming and Scripting

adding text to a file

Hi All I am making a script in which.I have a problem i try to discribe. File1 content need to be append in file 2 but such as if content already exist then dont add. File1 IS Like this myname yourname hername hisname File2 %AddNameHere myname yourname hername hisname (3 Replies)
Discussion started by: aliahsan81
3 Replies

4. Shell Programming and Scripting

Adding Text To Middle Of File

Hi I am trying to write a bash script to add a line of text to the middle of a file. The way I worked it out was to calculate the number of lines and divide by 2. The file I am using is called newfile and it just contains lines of data. The new file I have created I have called midfile and... (7 Replies)
Discussion started by: BundBash
7 Replies

5. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

6. Shell Programming and Scripting

Adding text into file

Hello, I after some assistance please. Below is a file I need to read and for each line write an output. My input file looks like this 2 20008 2003-08-26 2 20032 2003-08-26 2 20041 2003-08-26 2 20037 2003-08-26 2 20050 2003-08-26 6 ... (6 Replies)
Discussion started by: giles.cardew
6 Replies

7. Shell Programming and Scripting

adding a line to a text file

I have a tab delimited text file, id name distance 1 3325167 0.334561754018 2 3290488 0.389444269458 3 3288794 0.392312701782 4 3347602 0.392532202097 5 3295355 0.394394169485 I need to add a line after the header line. The first and third field of... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

8. Windows & DOS: Issues & Discussions

Script for adding users to file permissions

I need a script to add the following two users ids to the permissions for various files: IIS_WPG and IUSR_CowGirl. I am fairly familiar with scripting but haven't been able to figure out how to do this via a script. Manually doing it is slow. I don't want to create users but only add them to a... (2 Replies)
Discussion started by: Stu Loventhal
2 Replies

9. Shell Programming and Scripting

Script for adding users to file permissions

I need a script to add the following two users ids to the permissions for various files: IIS_WPG and IUSR_CowGirl. I am fairly familiar with scripting but haven't been able to figure out how to do this via a script. Manually doing it is slow. I don't want to create users but only add them to a... (2 Replies)
Discussion started by: Stu Loventhal
2 Replies

10. Shell Programming and Scripting

Bash to select text and apply it to a selected file in bash

In the bash below I am asking the user for a panel and reading that into bed. Then asking the user for a file and reading that into file1.Is the grep in bold the correct way to apply the selected panel to the file? I am getting a syntax error. Thank you :) ... (4 Replies)
Discussion started by: cmccabe
4 Replies
users-admin(1)							   User Commands						    users-admin(1)

NAME
users-admin - Configure local users and groups on the system. SYNOPSIS
users-admin [gnome-std-options] DESCRIPTION
users-admin enables the user to configure the local users and groups on the system. I also provides the ability to assign RBAC profiles to a user. OPTIONS
The following options are supported: gnome-std-options Standard options available for use with most GNOME applications. See gnome-std-options(5) for more informa- tion. EXAMPLES
Example 1: Running the main application. example% users-admin EXIT STATUS
The following exit values are returned: 0 Application exited successfully >0 Application exited with failure FILES
The following files are used by this application: /usr/bin/users-admin Executable for users and groups configuration. /var/spool/setup-tool-backends/data/users Where user template configurations are stored. /var/spool/setup-tool-backends/backup/users Backup directory for files that are modified. /var/run/setup-tool-backends/debug/users Debug logs can be found under here. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWgnome-system-tools | +-----------------------------+-----------------------------+ |Interface stability |Uncommitted | +-----------------------------+-----------------------------+ SEE ALSO
Latest version of the GNOME Desktop User Guide for your platform. time-admin(1), shares-admin(1), services-admin(1), network-admin(1), gnome-std-options(5), useradd(1M), usermod(1M), groupadd(1M), group- mod(1M), passwd(4), shadow(4), group(4), attributes(5) NOTES
YP/NIS, NIS+ and LDAP users should be aware that it's possible to have conflict with users configured in here with the result that an error will occur. You should ensure that local user's home accounts are located on local filesystems - e.g. creating a new entry in /home when it's mounted with automount will not work and as such the user may not be created. Written by Darren Kenny, Sun Microsystems Inc., 2006. SunOS 5.11 6 Nov 2006 users-admin(1)
All times are GMT -4. The time now is 12:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy