SHARE
TWEET

Untitled

a guest Jun 19th, 2017 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3.  
  4. #Specify the server name here (the name in the control panel)
  5. backuptarget=failbox
  6.  
  7. #eventually this will be auth so we can call against the API
  8. username=
  9. apikey=
  10.  
  11.  
  12. #This will be the format that the API returns the server list in.
  13.  
  14. serverlist=`echo "{"servers":[{"id":212190,"name":"Failbox"},{"id":212192,"name":"Failbox2"},{"id":234106,"name":"Failbox3"},{"id":307362,"name":"Nginx-test"},{"id":240055,"name":"samfailbox"}]}" | sed s/{/\ {/g`
  15.  
  16. numcolumn=`echo $serverlist | awk '{print NF}'
  17.  
  18.  
  19.  
  20. #This does a loop for the number of servers and parses them out into an array $server[]
  21. a=1
  22. echo "Processing Server List"
  23. for((i=2;i<$numcolumn;i++)) do
  24.  
  25.     server[$a]=`echo $serverlist | awk  '{print $"'$i'"}'`
  26.     let "a=$a+1"
  27. done
  28.  
  29.  
  30.  
  31.  
  32. #This matches the server to the name specified up there ^ and sets $id so we can initiate the backup
  33. shopt -s nocasematch
  34. for((q=1;q<${#server[*]};q++)) do
  35.  
  36.         serverhash=`echo ${server[$q]} | sed s/:/\ :\ /g | sed s/,/\ ,/g | sed s/}/\ }/g`
  37.     testvar=`echo $serverhash | awk '{print $6}'`
  38.        
  39.     if [[ $testvar = $backuptarget ]]
  40.     then
  41.         q=${#server[*]}
  42.         id=`echo $serverhash | awk '{print $3}'`
  43.     else
  44.         id=nomatch
  45.     fi
  46. done
  47. shopt -u nocasematch
  48.  
  49. #This exits the script if the server was not matched in the loop above
  50. if [[ $id = "nomatch" ]]
  51. then
  52.     echo "No Match found, check the backuptarget variable and spelling"
  53.     exit
  54. fi
  55.  
  56. echo "name = $testvar id = $id"
RAW Paste Data
Want to get better at Bash?
Learn to code Bash in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top