#! /bin/bash # Execute this script to generate the index, userid and passwd of a new user to the cluster. # The results are appended to the pre-existed file userpass.no.dat, which is then saved as a new file userpass.$(( 1 + $no )).dat no=$(ls /share/apps/configrepo/users_data/userpass.*.dat | awk -F'.' '{print $2}' | sort | awk 'END {print}') if [ -z "$no" ] then echo 'userpass.*.dat does not exist. To create a mock one userpass.0.dat' echo '0 mockuser0 1000 mockpassword' > /share/apps/configrepo/users_data/userpass.0.dat no=0 fi read -p "Enter new username : " user newno=$(( $no + 1 )) ######### to generate global userid coc-sshreachable hosts=$(cat /share/tmp/ssh-reachable.dat) rm -rf luid.dat for rn in $hosts do #ssh $rn "/share/apps/local/bin/coc-uid" >> luid.dat ssh -oStrictHostKeyChecking=no $rn "/share/apps/local/bin/coc-uid" >> luid.dat done userid=$(cat luid.dat | awk '{print $6}' | sort | uniq | awk 'END {print}') echo last userid from all nodes is $userid rm -rf luid.dat ######### end of to generate global userid userid=$(( $userid + 1 )) echo 'uid='$userid will be assigned echo '$no=' $no Index=$(( 1 + $(cat /share/apps/configrepo/users_data/userpass.$no.dat | awk 'END {print $1}') )) echo 'Index=' $Index passwd=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 9 | head -n 1) echo $Index $user $userid $passwd > /share/apps/configrepo/users_data/newuser.dat echo newuser.dat is created in /share/apps/configrepo/users_data/newuser.dat uid=$userid newuser=$user test_password=$passwd echo $Index $uid $newuser $test_password #useradd -u $uid -g users -p $test_password $newuser hosts=$(cat /share/tmp/ssh-reachable.dat | awk '{if ($1 != "192.168.1.10") print $1}' | awk '$1!= "anicca" ') echo 'available nodes are' $hosts echo ' ' #command="useradd -u $uid -g users -p $(openssl passwd -6 "$test_password") $newuser" #command="useradd -u $uid -g users $newuser" command="useradd -u $uid -g users -p $(openssl passwd -1 $test_password) $newuser" for i in $hosts do echo entering node "$i" echo $command #pdsh -R ssh -w "$i" "$command" #command="echo -e "$test_password\n$test_password\n" | passwd $newuser" #command='echo -e "$test_password"\'n'"$test_password" | passwd $newuser' #command=useradd -u $uid -g users -s /bin/bash -p $(echo "$password" | openssl passwd -1 -stdin) $username #echo $command pdsh -R ssh -w "$i" useradd -u $uid -g users -p $(openssl passwd -1 $test_password) $newuser done