Send_files_bash/distribute.sh
2022-03-25 05:22:02 +01:00

74 lines
2.0 KiB
Bash

#!/bin/bash
## Author Oriol Filter
# Date 16/02/2022
## Find which user is the correct one
### VAR
export _USERS="$(cat ./users)"
export _PROXY_ROUTES="$(cat ./proxy_routes)"
### Main
sed '/^$/d' h | tee ./curr_h >/dev/null # remove empty lines
printf "Attempting to SSH\n"
for username in $_USERS
do
printf "\033[0;33m ${username}\n\033[0m"
cat > "./${username}/h"
for hostname in $(cat ./curr_h)
do
printf "${hostname}: -->"
sshpass -f "./${username}/p" ssh -q -o StrictHostKeyChecking=no -T "${username}@${hostname}" 'echo true' &> /dev/null &&
printf "${hostname}: \033[1;32mYES \033[0m\n" &&
printf "${hostname}\n" | tee -a "./${username}/h" > /dev/null ||
printf "${hostname}: \033[1;31mNo \033[0m\n"
done
diff --new-line-format="" --unchanged-line-format="" ./curr_h "${username}/h" > left_h
mv ./left_h ./curr_h
done
mv curr_h discards_h
# Proxy / Triangulate
for proxy in $_PROXY_ROUTES
do
printf "\033[0;33m ${username}\n\033[0m"
for username in $_USERS
do
false
# printf "\033[0;33m ${username}\n\033[0m"
# rm ./${username}/h
# touch ./${username}/h
# for hostname in $(cat ./curr_h)
# do
# printf "${hostname}: -->"
# sshpass -f "./${username}/p" ssh -q -o StrictHostKeyChecking=no -T "${username}@${hostname}" 'echo true' &> /dev/null &&
# printf "${hostname}: \033[1;32mYES \033[0m\n" &&
# printf "${hostname}\n" | tee -a "./${username}/h" > /dev/null ||
# printf "${hostname}: \033[1;31mNo \033[0m\n" < "./${username}/p"
# done
# diff --new-line-format="" --unchanged-line-format="" ./curr_h "${username}/h" > left_h
# mv ./left_h ./curr_h
done
done
mv curr_h discards_h
printf "Distributed hosts\n"
for username in $_USERS
do
printf "\033[0;32m ${username}\n\033[0m"
awk '{ printf" %s\n",$0 }' < "./${username}/h"
done
printf "\033[0;31mDISCARDS:\033[0m\n"
awk '{ printf" %s\n",$0 }' < ./discards_h
printf "Discards are stored in './discards_h'\n"
bash ./send_files.sh