# add new user to local node with specified uid and passwd by reading the content from /share/apps/configrepo/users_data/newuser.dat /share/apps/local/bin/coc-check_user_local username=$(cat /share/apps/configrepo/users_data/newuser.dat | awk '{print $2}') uid=$(cat /share/apps/configrepo/users_data/newuser.dat | awk '{print $3}') passwd=$(cat /share/apps/configrepo/users_data/newuser.dat | awk '{print $4}') #echo 'passwd=' $passwd frontend=$(i=192.168.1.10; command='hostname'; ssh -X -Y -oStrictHostKeyChecking=no $i "$command") echo 'frontend=' $frontend currenthost=$(hostname) echo 'currenthost=' $currenthost if [ "$(cat /share/apps/configrepo/users_data/addstatus.dat)" = 'yes' ]; then # echo 'frontend=' $frontend # echo 'currenthost=' $currenthost echo adding $username to $currenthost useradd -u $uid -g users -s /bin/bash -p $(echo "$passwd" | openssl passwd -1 -stdin) $username echo 'user' $username 'with uid' $uid 'has been added to /etc/passwd' in $currenthost if [[ $currenthost =~ $frontend ]] then # do this in frontend echo $currenthost is the same as $frontend. echo Not to modify /etc/fstab in $currenthost echo 'To modify /etc/exports in' $currenthost cp /etc/exports /etc/exports.orig phrase2=$(cat /etc/exports | awk '/home/' | awk 'NR==1' | awk 'FS=" " {print $2}') echo '/home/'$username $phrase2 > temp; cat /etc/exports >> temp; mv temp /etc/exports else # do this in nodes echo $currenthost is not the same as $frontend. echo 'To modify /etc/fstab in' $currenthost echo 'before mounting' $username mount 192.168.1.10:/home/$username /home/$username echo 'after mounting' $username cp /etc/fstab /etc/fstab.orig echo '/etc/fstab modified for' $username echo '192.168.1.10:/home/'$username '/home/'$username 'nfs nosuid,rw,sync,hard,intr 0 0' >> /etc/fstab echo 'Not to modify /etc/exports in' $currenthost fi gen_bashrc.txt else echo 'user' $username 'already existed or uid' $uid 'is not uniq in /etc/passwd'. Not adding the user $username to $currenthost fi echo 'add local user' $username done mount -a