Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # retrieveHosts.sh
- # Available host file retrieving script
- #
- # Description:
- # This script tries retrieving the list with available hosts from different hosts.
- # If succesfull the script will place the host.txt file at ~/recieved/
- # This script needs hostsToTxt.sh to be located at ~/scripts/ in order to function
- # This scripts supposes you are using an ssh-agent
- # If not this might also work but you will be typing your password a lot.
- # Easily setting up an ssh-agent can be done with my other script init_ssh-agent.sh.
- #
- # Version: 1.0
- # Author: Dieter Castel
- # License: Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
- # See: http://creativecommons.org/licenses/by-nc-sa/3.0/ for more info.
- # Variables:
- # Place of the hostsToTxt.sh script. You can edit it if you want to move the script.
- scriptpath=~/scripts/hostsToTxt.sh
- # Output directory of the script.
- outputdir=~/recieved/
- # List of the hosts that will be tried. You can expand this if you want more redundancy.
- possiblehosts=(ham genk herent mol zwalm)
- # Boolean that tells the script if it failed all the hosts.
- failure=true
- # Make the recieved directory.
- mkdir $outputdir
- # Iterate over all the possible hosts.
- for currentHost in $possiblehosts;
- do
- echo "Will try ssh/scp with login $USER @ $currentHost"
- # Try to run the hostToTxt script on the currentHost.
- if ssh "$USER"@"$currentHost".cs.kotnet.kuleuven.be 'bash -s' < "$scriptpath";
- then
- # If succesfull transfer the file from the host to the current machine.
- if scp "$USER"@"$currentHost".cs.kotnet.kuleuven.be:/home/"$USER"/toSend/hosts.txt "$outputdir";
- then
- # If the transfer succeeds the script succeeds and we break out of the for loop.
- failure=false
- echo "hosts.txt succesfully transferd from $currentHost to $outputdir"
- break;
- else
- echo "$currentHost failed to transfer the file";
- fi;
- else
- echo "$currentHost failed";
- fi
- done
- # Report failure
- if $failure; then
- echo "Every try failed";
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement