Skip to main content

Thread: User add script


hi,

made script supposed add users tab delimited text file.
when ran it, users added (or seems) don't show on users , groups. after reboot, says gdm user not exist , user (at time sudoer) no longer sudoers user.

can login in shell, files there.
here script ran:

code:
#!/bin/bash  if [$1 == ""]; exit 0; fi  while read line   ifs=""  username=`echo $line | cut -f 1`  fname=`echo $line | cut -f 2`  lname=`echo $line | cut -f 3`  description=`echo $line | cut -f 4`  homedir=`echo $line | cut -f 5`  loginscript=`echo $line | cut -f 6`  profile=`echo $line | cut -f 7`  pwdexpire=`echo $line | cut -f 8`  pwdnotexpire=`echo $line | cut -f 9`  echo "username: $username name: $fname $lname description: $description"  sudo useradd -c "$fname $lname" -d "/home/$username" -n -m  $username  done < $1
can guys me? had recover system, need know wrong in script, since single
code:
useradd -c "aaa" -d "/home/aaa" -n -m aaa
runs fine.

again.

the first line (after hash-bang) wrong @ least. [ command, it's not part of if-syntax, arguments must delimited spaces other command.

parsing file, don't see point in using cut, use built in read command.

code:
#!/bin/bash (($#)) || exit   # exit if number of arguments 0 while ifs=$'\t' read -r username fname lname desc homedir etc;   useradd -c "$fname $lname" ... done < "$1"
not sure why script break added users though. take backup of /etc/passwd, compare /etc/passwd after script has run , see did ...


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk User add script


Ubuntu

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support