#!/bin/bash
initial="/"
usrname=`cut -d ":" -f1 users.txt`
password=`cut -d '"' -f3 users.txt|cut -d ":" -f2`
comment=`cut -d '"' -f2,3 users.txt|cut -d ":" -f1`
path=`cut -d "/" -f2,3 users.txt`
totalpath="$initial$path"
while read line
do
useradd -p "$password" -c "$comment" -m -d "$totalpath" "$usrname"
done < "users.txt"
I am trying to add multiple users using text file. I am getting "syntax error near unexpected token `done'". All my stored variables are coming out perfectly. I tested it using echo command. However, when I run the loop, the error message pops up and users are not getting created.
For your reference this is how my text file looks like:
acdeng:"ADLER CHARLES DAVID",00-9388,x0753,Engineering:acc944:/home/Engineering
ardsal:"ANSELL ROBERT D",14-2675,x1624,Sales:acc944:/home/Sales
$password
,$comment
et al aren't going to be updated each time through thewhile
loop; only$line
is updated, and you don't use its value. – Keith Thompson Dec 4 '13 at 23:44