-1
私は、AddUsers.shというbashスクリプトを持っています。このように、変数をLinuxコマンドがbashで動作しない
[email protected];1927/09/04;sudo,visitor;/visitorData
をして返す:スクリプトは、このような行を取る必要があります
name=john
surname=mccarthy
bdate=1927/09/04
uname=mccjoh
pass=1927
groups(array)=sudo, visitor
folder=/visitorData
を私はスクリプトを実行し、それに必要なテキストファイルを与えるとき、「groupaddの」ことを私にtellilngされます'chgrp' 'chmod'と 'chage'はすべてエラーです。誰にでも私に教えて/フィードバックをくれますか?
ご協力いただきありがとうございます。
#!/bin/bash
#check for file
while [ ! -f $file ]
do
#ask user for filename
echo What is the filename?
#reading input as file name
read file
if [ ! -f $file ]
then
echo "File not found!"
else
echo "File found!"
fi
done
#process each line and make a user from the data
cat "$file" | while read line
do
name=`echo $line | sed 's/^\(.*\)\..*\@.*$/\1/g'`
surname=`echo $line | sed 's/^.*\.\(.*\)\@.*$/\1/g'`
bdate=`echo $line | sed 's/^.*;\(.*\);.*;.*$/\1/g'`
#set groups to tokenize
groups=`echo $line`
folder=`echo $line`
temp2=`echo $name | sed 's/^\(...\).*$/\1/g'`
temp1=`echo $surname | sed 's/^\(...\).*$/\1/g'`
user="${temp1}${temp2}"
#pass must be first 4 numbers of birthdate
pass= ${bdate:0:4}
#tokenise group + add to array
declare -a groupArray
IFS=" "
groupArray=(`echo $groups | tr "," " "`)
#create groups if not existing.
for i in ${groupArray[@]}
do
if [ getent group $i ]
then
echo "group exists"
else
groupadd $i
fi
done
#Create shared folders if not existing.
if [ ! -d $folder ];
then
mkdir -p $folder
fi
#Create groups for shared folders
gname=`echo "${folder:1}"`
groupadd $gname
#Set group as owner of directory and change permissions
chgrp -R $gname $folder
chmod -R 770 $folder
#create user and add to groups
if [ grep "^${user}:" /etc/passwd ]
then
echo "user exists already!"
else
#Create user
useradd -m -d /home/$user -p $pass $user
#Add user to groups
for i in ${groupArray[@]}
do
usermod -a -G $i $user
done
#Add user to shared group
usermod -a -G $gname $user
fi
#force password change
chage -d 0 $user
done
がhttp://shellcheck.net –
また代わりの掲示を通して、あなたのスクリプトを実行します。chmodた $スクリプト全体では、エラーの発生場所に絞り込むと便利です。スクリプトがその状態を吐き出したいところに 'set + x'を追加し、停止させたいところに' set-x'を追加して、ステップを進めてください。http://stackoverflow.com/help/mcve –
通常は、スクリプト全体を監視することができない場合は、ファイルの先頭に '#!/ bin/bash'の後ろに' set + x'を置いてください。 – jiveturkey