How to create a user account from a text file input
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
Need to create a bash script to create a username from a file which contains below (username home directory full name)
drs /home/drs Paranas Theruwalan
My script:
!#/bin/bash
#call data from file
file="file.txt"
USERNAME=$(cat file.txt | cut -d: -f1)
USER_FULLNAME=$(cat file.txt | cut -d: -f2)
useradd -m ($USERNAME) -c ($USER_FULNAME)
I getting invalid username error.
accounts
add a comment |Â
up vote
0
down vote
favorite
Need to create a bash script to create a username from a file which contains below (username home directory full name)
drs /home/drs Paranas Theruwalan
My script:
!#/bin/bash
#call data from file
file="file.txt"
USERNAME=$(cat file.txt | cut -d: -f1)
USER_FULLNAME=$(cat file.txt | cut -d: -f2)
useradd -m ($USERNAME) -c ($USER_FULNAME)
I getting invalid username error.
accounts
Related: How to add users from data in a text file
â steeldriver
Aug 15 at 10:09
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Need to create a bash script to create a username from a file which contains below (username home directory full name)
drs /home/drs Paranas Theruwalan
My script:
!#/bin/bash
#call data from file
file="file.txt"
USERNAME=$(cat file.txt | cut -d: -f1)
USER_FULLNAME=$(cat file.txt | cut -d: -f2)
useradd -m ($USERNAME) -c ($USER_FULNAME)
I getting invalid username error.
accounts
Need to create a bash script to create a username from a file which contains below (username home directory full name)
drs /home/drs Paranas Theruwalan
My script:
!#/bin/bash
#call data from file
file="file.txt"
USERNAME=$(cat file.txt | cut -d: -f1)
USER_FULLNAME=$(cat file.txt | cut -d: -f2)
useradd -m ($USERNAME) -c ($USER_FULNAME)
I getting invalid username error.
accounts
accounts
edited Aug 15 at 9:51
msp9011
3,46643862
3,46643862
asked Aug 15 at 9:23
Suresh Silva
1
1
Related: How to add users from data in a text file
â steeldriver
Aug 15 at 10:09
add a comment |Â
Related: How to add users from data in a text file
â steeldriver
Aug 15 at 10:09
Related: How to add users from data in a text file
â steeldriver
Aug 15 at 10:09
Related: How to add users from data in a text file
â steeldriver
Aug 15 at 10:09
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
0
down vote
First you should remove the () for using variables:useradd -m $USERNAME -c $USER_FULNAME
Second check the output of username, maybe it includes invalid characters.
add a comment |Â
up vote
0
down vote
Here you go:
#!/bin/bash
#call data from file
FILE="file.txt"
USERNAME=$(cut -d " " -f 1 $FILE)
USER_FULLNAME=$(cut -d " " -f 3,4 $FILE)
useradd -m -c "$USER_FULLNAME" "$USERNAME"
add a comment |Â
up vote
0
down vote
What are your separators, space or colon? You example suggests space, your code suggests colon.
You can do that in bash.
#!/bin/bash
file="file.txt"
while IFS=: read USERNAME USER_HOME USER_FULLNAME; do
useradd -m -c "$USER_FULLNAME" -d "$USER_HOME" "$USERNAME"
done < "$file"
This example assumes as input a file with lines like
drs:/home/drs:Paranas Theruwalan
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
First you should remove the () for using variables:useradd -m $USERNAME -c $USER_FULNAME
Second check the output of username, maybe it includes invalid characters.
add a comment |Â
up vote
0
down vote
First you should remove the () for using variables:useradd -m $USERNAME -c $USER_FULNAME
Second check the output of username, maybe it includes invalid characters.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
First you should remove the () for using variables:useradd -m $USERNAME -c $USER_FULNAME
Second check the output of username, maybe it includes invalid characters.
First you should remove the () for using variables:useradd -m $USERNAME -c $USER_FULNAME
Second check the output of username, maybe it includes invalid characters.
edited Aug 15 at 9:48
answered Aug 15 at 9:38
Amirk
11
11
add a comment |Â
add a comment |Â
up vote
0
down vote
Here you go:
#!/bin/bash
#call data from file
FILE="file.txt"
USERNAME=$(cut -d " " -f 1 $FILE)
USER_FULLNAME=$(cut -d " " -f 3,4 $FILE)
useradd -m -c "$USER_FULLNAME" "$USERNAME"
add a comment |Â
up vote
0
down vote
Here you go:
#!/bin/bash
#call data from file
FILE="file.txt"
USERNAME=$(cut -d " " -f 1 $FILE)
USER_FULLNAME=$(cut -d " " -f 3,4 $FILE)
useradd -m -c "$USER_FULLNAME" "$USERNAME"
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Here you go:
#!/bin/bash
#call data from file
FILE="file.txt"
USERNAME=$(cut -d " " -f 1 $FILE)
USER_FULLNAME=$(cut -d " " -f 3,4 $FILE)
useradd -m -c "$USER_FULLNAME" "$USERNAME"
Here you go:
#!/bin/bash
#call data from file
FILE="file.txt"
USERNAME=$(cut -d " " -f 1 $FILE)
USER_FULLNAME=$(cut -d " " -f 3,4 $FILE)
useradd -m -c "$USER_FULLNAME" "$USERNAME"
answered Aug 15 at 10:09
mikst
967
967
add a comment |Â
add a comment |Â
up vote
0
down vote
What are your separators, space or colon? You example suggests space, your code suggests colon.
You can do that in bash.
#!/bin/bash
file="file.txt"
while IFS=: read USERNAME USER_HOME USER_FULLNAME; do
useradd -m -c "$USER_FULLNAME" -d "$USER_HOME" "$USERNAME"
done < "$file"
This example assumes as input a file with lines like
drs:/home/drs:Paranas Theruwalan
add a comment |Â
up vote
0
down vote
What are your separators, space or colon? You example suggests space, your code suggests colon.
You can do that in bash.
#!/bin/bash
file="file.txt"
while IFS=: read USERNAME USER_HOME USER_FULLNAME; do
useradd -m -c "$USER_FULLNAME" -d "$USER_HOME" "$USERNAME"
done < "$file"
This example assumes as input a file with lines like
drs:/home/drs:Paranas Theruwalan
add a comment |Â
up vote
0
down vote
up vote
0
down vote
What are your separators, space or colon? You example suggests space, your code suggests colon.
You can do that in bash.
#!/bin/bash
file="file.txt"
while IFS=: read USERNAME USER_HOME USER_FULLNAME; do
useradd -m -c "$USER_FULLNAME" -d "$USER_HOME" "$USERNAME"
done < "$file"
This example assumes as input a file with lines like
drs:/home/drs:Paranas Theruwalan
What are your separators, space or colon? You example suggests space, your code suggests colon.
You can do that in bash.
#!/bin/bash
file="file.txt"
while IFS=: read USERNAME USER_HOME USER_FULLNAME; do
useradd -m -c "$USER_FULLNAME" -d "$USER_HOME" "$USERNAME"
done < "$file"
This example assumes as input a file with lines like
drs:/home/drs:Paranas Theruwalan
answered Aug 15 at 10:19
RalfFriedl
3,7001523
3,7001523
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f462708%2fhow-to-create-a-user-account-from-a-text-file-input%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Related: How to add users from data in a text file
â steeldriver
Aug 15 at 10:09