Как создать несколько пользователей в операционной системе Linux с помощью сценариев оболочки? - PullRequest
0 голосов
/ 09 октября 2018

Этот сценарий оболочки создает несколько пользователей в Linux, но возвращает ошибку ниже.

UserScript.sh: 21: UserScript.sh: Syntax error: "(" unexpected
(expecting "fi")

Вот сценарий:

#!/bin/bash
filein="anotherfile.csv"
IFS=$`\n`

if [! -f "$filein" ]
then
  echo "can not find file $filein"
else
  #create arrays of groups full name, and usernames
  groups=(`cut -d: -f 6 "$filein" | sed 's/ //'`)
  fullname=(`cut -d: -f 1 "$filein"`)
  userid=(`cut -d: -f 2 "$filein"`)
  usernames=(`cut -d: -f 1 "$filein" | tr [A-Z] [a-z] | awk '{print substr($1,1,1) $2}'`)

  #check if the group exits, if not then creates it
  for group in ${group[*]}
  do
  grep -q "$group" /etc/group : let x=$?
  if [ $x -eq 1 ]
  then 
  groupadd "$group"
  fi
  done

  #create the user accounts, adds them to groups, and sets passwords
  #then once account is created, mails the account
  x=0
  created=0
  for user in ${usernames[*]}
  do
  useradd -n -c ${fullnames[$x]} -g "${groups[$x]}" $user 2> dev/null
  if [ $? -eq 0 ]
  then
  let created=$created+1
  fi
  #this creates the password for the user suppresses ouput of passwd
  #the -p in the useradd function doesn't set it properly
  echo "${userid[$x]}" | passwd --stdin "$user" > /dev/null

  #sends mails to user
  echo "welcome your account has been created. your username is $user and temporary passwords is \"$password\" without quotation. "
 |mail -s "New Account for $user" -b root $user
  x=$x+1
  echo -n "..."
  sleep -25
  done
  sleep -25
  echo " "
  echo "complete. $created accounts have been created."
fi
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...