#! /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 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 #echo $Index $user $userid $passwd 'will be appended to' userpass.$newno.dat if it passes coc-check_user_global rm -rf /share/apps/configrepo/users_data/addstatus_global.dat /share/apps/local/bin/coc-check_user_global if [ ! -f /share/apps/configrepo/users_data/addstatus_global.dat ]; then echo 'passes coc-check_user_global check' cp /share/apps/configrepo/users_data/userpass.$no.dat temp.dat echo $Index $user $userid $passwd >> temp.dat mv temp.dat /share/apps/configrepo/users_data/userpass.$newno.dat echo $Index $user $userid $passwd are appended to /share/apps/configrepo/users_data/userpass.$newno.dat else # cat /share/apps/configrepo/users_data/addstatus_global.dat; echo 'does not pass coc-check_user_global check.' rm -rf /share/apps/configrepo/users_data/newuser.dat echo newuser.dat is removed from /share/apps/configrepo/users_data/newuser.dat fi