#! /bin/bash # to sync all users across all nodes in the cluster # if an user in /etc/passwd in the frontend does not exist in a node, add the user to that node (CASE 4) # if an user in /etc/passwd in the frontend exists in a node but with a different uid, change the uid in the node so that it becomes tally with that in the frontend's.(CASE 2) # if an user in /etc/passwd in the frontend exists in a node with the the same uid, do nothing. (CASE 3) # if an user in /etc/passd in the frontend shares a common uid with an user ($usernode) in a node, change the uid of the user $usernode in the node.(CASE 1) coc-sshreachable #hosts=$(cat /share/tmp/ssh-reachable.dat) declare -a hosts=($(cat /share/tmp/ssh-reachable.dat)) #($(cat /etc/hosts | awk 'NF==4 {print $4}' | uniq | sort)) alh=${#hosts[@]} declare -a username=($(cat /etc/passwd | awk -F":" '{print $1, $3}' | awk '{if($2>=1000 && $2<4000) {print $1}}')) declare -a uid=($(cat /etc/passwd | awk -F":" '{print $1, $3}' | awk '{if($2>=1000 && $2<4000) {print $2}}')) alength=${#username[@]} rm -rf syncusers.dat /share/apps/configrepo/users_data/syncusers.dat for (( i=1; i<${alength}+1; i++ )); do #echo 'i=' $i ${username[$i-1]} ${uid[$i-1]} #${u2[$i-1]} echo 0000 ${username[$i-1]} ${uid[$i-1]} mockpaswd > /share/apps/configrepo/users_data/newuser.dat for (( j=1; j<${alh}+1; j++ )); do ################## echo 'i=' $i ${username[$i-1]} ${uid[$i-1]} 'j='$j 'host=' ${hosts[$j-1]} ssh -oStrictHostKeyChecking=no ${hosts[$j-1]} "sh /share/apps/local/bin/coc-check_user_local" >> /share/apps/configrepo/users_data/syncusers.dat cat /share/apps/configrepo/users_data/syncusers.dat | uniq > temp.dat mv temp.dat /share/apps/configrepo/users_data/syncusers.dat sed -i 's/compute-0-/c/g' /share/apps/configrepo/users_data/syncusers.dat cat /share/apps/configrepo/users_data/syncusers.dat | awk 'END {print}' echo ' ' ################## done done #/share/apps/local/bin/coc-cases