Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Specify the server name here (the name in the control panel)
- backuptarget=failbox
- #eventually this will be auth so we can call against the API
- username=
- apikey=
- #This will be the format that the API returns the server list in.
- 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`
- numcolumn=`echo $serverlist | awk '{print NF}'
- #This does a loop for the number of servers and parses them out into an array $server[]
- a=1
- echo "Processing Server List"
- for((i=2;i<$numcolumn;i++)) do
- server[$a]=`echo $serverlist | awk '{print $"'$i'"}'`
- let "a=$a+1"
- done
- #This matches the server to the name specified up there ^ and sets $id so we can initiate the backup
- shopt -s nocasematch
- for((q=1;q<${#server[*]};q++)) do
- serverhash=`echo ${server[$q]} | sed s/:/\ :\ /g | sed s/,/\ ,/g | sed s/}/\ }/g`
- testvar=`echo $serverhash | awk '{print $6}'`
- if [[ $testvar = $backuptarget ]]
- then
- q=${#server[*]}
- id=`echo $serverhash | awk '{print $3}'`
- else
- id=nomatch
- fi
- done
- shopt -u nocasematch
- #This exits the script if the server was not matched in the loop above
- if [[ $id = "nomatch" ]]
- then
- echo "No Match found, check the backuptarget variable and spelling"
- exit
- fi
- echo "name = $testvar id = $id"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement