commit d7fd893a843dc58921b80c0fe9f5a4923dde24b1 Author: ofilter Date: Thu Mar 10 06:58:26 2022 +0100 first push diff --git a/README.md b/README.md new file mode 100644 index 0000000..f97317b --- /dev/null +++ b/README.md @@ -0,0 +1,60 @@ +# Experimental usage + +Download the scripts **send_files.sh** and **distribute.sh** + +Create the files **users** and **files_to_send** + +#### users + +List of users to use doesn't allow spaces in the username + +```text +user1 user2 +user3 +``` + +Create a folder for each user adn a file named *p* which contains the password in flat text + + +#### files_to_send + +List of files to send, doesn't allow spaces in the same file + + +```text +file1 file2 +file3 +``` + +Place the files on the working structure (aka. script folder) + + +## Create the following directory structure + +```bash +./ <-- working structure (execute script at this lvl aka. use cd) +./distribute.sh +./send_files.sh +./files_to_send +./users + +#### files to send +./file1 +./file2 +./file3 + +### users +./user1/ <---- directory from the user +./user1/p <---- txt with password of the user + +./user2/ <---- directory from the user +./user2/p <---- txt with password of the user +``` + +##### + +Execute + +```bash +$ bash ./distribute.sh +``` \ No newline at end of file diff --git a/distribute.sh b/distribute.sh new file mode 100644 index 0000000..86af9bb --- /dev/null +++ b/distribute.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +## Author Oriol Filter +# Date 16/02/2022 + + +## Find which user is the correct one + +### VAR +export _USERS="$(cat ./users)" + + +### Main + +sed '/^$/d' h | tee ./curr_h >/dev/null # remove empty lines + +printf "Attempting to SSH\n" + +for u in $_USERS +do + printf "\033[0;33m $u\n\033[0m" + rm ./${u}/h + touch ./${u}/h + for h in $(cat ./curr_h) + do + printf "${h}: -->" +# sshpass -f "./${u}/p" ssh -q -o GSSAPIAuthentication=no -o StrictHostKeyChecking=no -T "${u}@${h}" 'echo true' &> /dev/null && + + sshpass -f "./${u}/p" ssh -q -o StrictHostKeyChecking=no -T "${u}@${h}" 'echo true' &> /dev/null && + printf "${h}: \033[1;32mYES \033[0m\n" && + printf "${h}\n" | tee -a "./${u}/h" > /dev/null || + printf "${h}: \033[1;31mNo \033[0m\n" < "./${u}/p" + done + diff --new-line-format="" --unchanged-line-format="" ./curr_h "${u}/h" > left_h + mv ./left_h ./curr_h +done +mv curr_h discards_h + +printf "Distributed hosts\n" + +for u in $_USERS +do + printf "\033[0;32m $u\n\033[0m" + awk '{ printf" %s\n",$0 }' < "./${u}/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 diff --git a/files_to_send b/files_to_send new file mode 100644 index 0000000..a16e67c --- /dev/null +++ b/files_to_send @@ -0,0 +1,2 @@ +file1 file2 +file3 \ No newline at end of file diff --git a/send_files.sh b/send_files.sh new file mode 100644 index 0000000..191ca47 --- /dev/null +++ b/send_files.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +## Author Oriol Filter +# Date 10/03/2022 + +## Send scripts/files to the servers + +### VAR +# check if _users is empty + +# _USERS="ibmuser bs2cloud" +_USERS="$(cat ./users)" + +#_USERS="$_USERS" +_FILES="$(cat ./files_to_send)" + +printf "Sending files to /tmp\n" + +### Main + +for u in $_USERS +do + printf "\033[0;33m $u\033[0m\n" + + for h in $(cat "${u}/h") + do + printf "\033[1;34m $h\033[0m\n" + for _F in $_FILES + do + sshpass -f "./${u}/p" scp -q -o StrictHostKeyChecking=no "$_F" "${u}@${h}:/tmp/" && + printf "\t${_F}: \033[1;32mYES \033[0m\n" || + printf "\t${_F}: \033[1;31mNo \033[0m\n" + done + printf " -----------\n" + done +done + +printf "\033[1;32mDONE \033[0m\n" diff --git a/users b/users new file mode 100644 index 0000000..3c466eb --- /dev/null +++ b/users @@ -0,0 +1,2 @@ +user1 user2 +user3 \ No newline at end of file