#! /bin/bash # to sync the password of all users (except for root) across all nodes in the cluster (except in the frontend) # must lauch this script from the frontend coc-sshreachable declare -a hosts=($(cat /share/tmp/ssh-reachable.dat | awk '{if ($1 != "192.168.1.10") print $1}')) 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[@]} for (( i=1; i<${alength}+1; i++ )); do ####################################### ### to abstract the password of ${username[$i-1]} from /share/apps/configrepo/users_data/userpass.xx.dat 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:' $taf passwd=$(cat $taf | grep "${username[$i-1]}" | awk '{print $4}') echo '${username[$i-1]} $passwd:' echo ${username[$i-1]} $passwd ####################################### echo 0000 ${username[$i-1]} ${uid[$i-1]} $passwd > /share/apps/configrepo/users_data/newuser.dat echo '$i:' $i, '/share/apps/configrepo/users_data/newuser.dat:' cat /share/apps/configrepo/users_data/newuser.dat ssh -oStrictHostKeyChecking=no ${hosts[$j-1]} "coc-pwlssh3" #coc-pwlssh3 echo ' ' done