#! /bin/bash ## Read the information from /share/apps/configrepo/users_data/syncusers.dat (CASE 1,2,3,4) and implement the necessary corrections for an user in a node. #CASE 3: users are properly synced declare -a u2a=($(cat /share/apps/configrepo/users_data/syncusers.dat | grep 'CASE 3' | awk '{print $4}')) declare -a id=($(cat /share/apps/configrepo/users_data/syncusers.dat | grep 'CASE 3' | awk '{print $13}')) declare -a n2a=($(cat /share/apps/configrepo/users_data/syncusers.dat | grep 'CASE 3' | awk '{print $21}')) alen=${#u2a[@]} if [ $alen -eq 0 ]; then echo "No CASE 3" else echo 'CASE 3: The following users are synced in the local nodes. Will do nothing.' echo 'alen=' $alen for (( i=1; i<${alen}+1; i++ )); do echo 'i=' $i ${u2a[$i-1]} ${id[$i-1]} ${n2a[$i-1]} done echo ' ' fi #CASE 2: To modify uid of user in local nodes declare -a u2a=($(cat /share/apps/configrepo/users_data/syncusers.dat | grep 'CASE 2' | awk '{print $4}')) declare -a id=($(cat /share/apps/configrepo/users_data/syncusers.dat | grep 'CASE 2' | awk '{print $13}')) declare -a id2m=($(cat /share/apps/configrepo/users_data/syncusers.dat | grep 'CASE 2' | awk '{print $18}')) declare -a n2a=($(cat /share/apps/configrepo/users_data/syncusers.dat | grep 'CASE 2' | awk '{print $20}')) alen=${#u2a[@]} if [ $alen -eq 0 ]; then echo "No CASE 2" nc2='true' else echo 'CASE 2: To modify the uid of users in local nodees' echo 'alen=' $alen for (( i=1; i<${alen}+1; i++ )); do echo 'i=' i 'The uid' ${id2m[$i-1]} 'of user' ${u2a[$i-1]} 'in' ${n2a[$i-1]} 'is to be changed to' ${id[$i-1]} echo '0000' ${u2a[$i-1]} ${id[$i-1]} mockpasswd > /share/apps/configrepo/users_data/newuser.dat ssh -X -Y -oStrictHostKeyChecking=no ${n2a[$i-1]} "/share/apps/local/bin/coc-usermod_uid_local" done echo ' ' fi # {print "} #CASE 4: To add user to compute node declare -a u2a=($(cat /share/apps/configrepo/users_data/syncusers.dat | grep 'CASE 4' | awk '{print $4}')) declare -a id2a=($(cat /share/apps/configrepo/users_data/syncusers.dat | grep 'CASE 4' | awk '{print $7}')) declare -a n2a=($(cat /share/apps/configrepo/users_data/syncusers.dat | grep 'CASE 4' | awk '{print $12}')) alen=${#u2a[@]} if [ $alen -eq 0 ]; then echo "No CASE 4" nc4='true' else echo 'CASE 4: To add the following users in local nodes' echo 'alen=' $alen for (( i=1; i<${alen}+1; i++ )); do ####################################### ### to abstract the password of ${u2a[$i-1]} from /share/apps/configrepo/users_data/userpass.xx.dat usr=${u2a[$i-1]} number=$(ls /share/apps/configrepo/users_data/userpass.* | awk -F "." '{print $2}' | sort | awk 'END {print}') taf=/share/apps/configrepo/users_data/userpass.$number.dat #echo $taf passw=$(cat $taf | grep "${u2a[$i-1]}" | awk '{print $4}') # echo "${u2a[$i-1]}" "$passw" ####################################### echo 'i=' $i To add user ${u2a[$i-1]} with uid ${id2a[$i-1]} with passwd "$passw" in ${n2a[$i-1]} # echo 'i=' $i ${u2a[$i-1]} ${n2a[$i-1]} echo '0000' ${u2a[$i-1]} ${id2a[$i-1]} "$passw" > /share/apps/configrepo/users_data/newuser.dat ssh -X -Y -oStrictHostKeyChecking=no ${n2a[$i-1]} "/share/apps/local/bin/coc-adduser_local" done echo ' ' fi #CASE 1: A common uid is associated with distinct users in the frontend and the nodes. The uid of the user in the nodes will be modified. declare -a uf=($(cat /share/apps/configrepo/users_data/syncusers.dat | grep 'CASE 1' | awk '{print $4}')) declare -a un=($(cat /share/apps/configrepo/users_data/syncusers.dat | grep 'CASE 1' | awk '{print $9}')) declare -a id=($(cat /share/apps/configrepo/users_data/syncusers.dat | grep 'CASE 1' | awk '{print $12}')) declare -a n2a=($(cat /share/apps/configrepo/users_data/syncusers.dat | grep 'CASE 1' | awk '{print $20}')) alen=${#n2a[@]} if [ $alen -eq 0 ]; then echo "No CASE 1" nc1='true' else echo 'CASE 1: To modify the uid of an user in a node that shares a common uid with another user in the frontend' echo 'alen=' $alen for (( i=1; i<${alen}+1; i++ )); do echo 'i=' $i 'The uid' ${id[$i-1]} 'is the same for user' ${uf[$i-1]} 'in the frontend and user' ${un[$i-1]} 'in the node' ${n2a[$i-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 -oStrictHostKeyChecking=no "/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 userid=$(( $userid + 1 )) rm -rf luid.dat ######### end of to generate global userid echo 'To change the uid' ${id[$i-1]} for user ${un[$i-1]} 'in the node' ${n2a[$i-1]} to $userid echo '0000' ${un[$i-1]} $userid mockpasswd > /share/apps/configrepo/users_data/newuser.dat ssh -X -Y -oStrictHostKeyChecking=no ${n2a[$i-1]} "/share/apps/local/bin/coc-usermod_uid_local" done echo ' ' fi if [ "$nc2" = 'true' ] && [ "$nc4" = 'true' ] && [ "$nc1" = 'true' ] then echo 'all users are synced' fi