Useradd Bash脚本 - 用户脚本:13:用户脚本:语法错误:“(”意外(期待“然后”)

时间:2017-05-13 12:47:13

标签: linux bash

我需要创建一个具有一些自动化功能的Bash脚本,以便从CSV文件创建用户帐户。我已完成脚本,代码如下。

#!/bin/bash
########################
# User Creation Script #
########################
filein="users.csv"
IFS=$'\n'

if [ ! -f "$filein" ]
then
 echo "File $filein cannot be found"
else

groups=(`cut -d: -f 3 "$filein"`)
fullnames=(`cut -d: -f 1 "$filein"`)
userid=(`cut -d: -f 4 "$filein"`)
usernames=(`cut -d: -f 2 "$filein"`)

# Checks to see if group exists, if not then its created
for group in ${groups[*]}
do
 grep -q "^$group" /home/group ; let x=$?
if [ $x  -eq 1 ]
then
  groupadd "$group"
fi
done

# Creates the user account, adds them to the group, and sets the password
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

echo "${userid[$x]}" | passwd -stdin "$user" > /dev/null

# Sends the user a mail message
echo "Your Acccount has been created! Your username is $user andyour      
temp password is \"$password\" without the quotes."
| mail -s "New Account for $user" -b root $user
x=$x+1
 echo -n "..."
  sleep .20
 done
  sleep .20
 echo " "
 echo "Complete. $created Accounts have been created."
fi

当我在终端中运行它时,我收到此错误:

  

Userscript:13:Userscript:语法错误:“(”意外(期待)   “然后”)

我目前正在使用Linux系统管理课程,所有这些对我来说都是新手。

0 个答案:

没有答案