SHARE
TWEET

retrieveHosts.sh

kuldietercastel Mar 2nd, 2013 23 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # retrieveHosts.sh
  2. # Available host file retrieving script
  3. #
  4. # Description:
  5. #       This script tries retrieving the list with available hosts from different hosts.
  6. #       If succesfull the script will place the host.txt file at ~/recieved/
  7. #       This script needs hostsToTxt.sh to be located at ~/scripts/ in order to function
  8. #       This scripts supposes you are using an ssh-agent
  9. #       If not this might also work but you will be typing your password a lot.
  10. #       Easily setting up an ssh-agent can be done with my other script init_ssh-agent.sh.
  11. #
  12. # Version:      1.0
  13. # Author:       Dieter Castel
  14. # License:      Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  15. #                       See: http://creativecommons.org/licenses/by-nc-sa/3.0/ for more info.
  16.  
  17. # Variables:
  18. #       Place of the hostsToTxt.sh script. You can edit it if you want to move the script.
  19. scriptpath=~/scripts/hostsToTxt.sh
  20. #       Output directory of the script.
  21. outputdir=~/recieved/
  22. #       List of the hosts that will be tried. You can expand this if you want more redundancy.
  23. possiblehosts=(ham genk herent mol zwalm)
  24. #       Boolean that tells the script if it failed all the hosts.
  25. failure=true
  26.  
  27.  
  28. # Make the recieved directory.
  29. mkdir $outputdir
  30.  
  31. # Iterate over all the possible hosts.
  32. for currentHost in $possiblehosts;
  33. do
  34.         echo "Will try ssh/scp with login $USER @ $currentHost"
  35.         # Try to run the hostToTxt script on the currentHost.
  36.         if ssh  "$USER"@"$currentHost".cs.kotnet.kuleuven.be 'bash -s' < "$scriptpath";
  37.         then
  38.                 # If succesfull transfer the file from the host to the current machine.
  39.                 if scp "$USER"@"$currentHost".cs.kotnet.kuleuven.be:/home/"$USER"/toSend/hosts.txt "$outputdir";
  40.                 then
  41.                         # If the transfer succeeds the script succeeds and we break out of the for loop.
  42.                         failure=false
  43.                         echo "hosts.txt succesfully transferd from $currentHost to $outputdir"
  44.                         break;
  45.                 else
  46.                         echo "$currentHost failed to transfer the file";
  47.                 fi;
  48.         else
  49.                 echo "$currentHost failed";
  50.         fi
  51. done
  52.  
  53. # Report failure
  54. if $failure; then
  55.         echo "Every try failed";
  56. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top