first push
This commit is contained in:
commit
d7fd893a84
60
README.md
Normal file
60
README.md
Normal file
@ -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
|
||||
```
|
52
distribute.sh
Normal file
52
distribute.sh
Normal file
@ -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
|
2
files_to_send
Normal file
2
files_to_send
Normal file
@ -0,0 +1,2 @@
|
||||
file1 file2
|
||||
file3
|
38
send_files.sh
Normal file
38
send_files.sh
Normal file
@ -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"
|
Loading…
x
Reference in New Issue
Block a user