Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
#!/bin/bash
get_token() {
token=`curl -k -s -X POST -H "Content-Type: application/json" -d '{"username":"'$wnamlogin'","password":"'$wnampassword'"}'  https://$wnam_address/api/2.0/authenticate | jq -r .access_token`
echo $token > /tmp/token
} 

STATUS="100" 
wnamlogin="admin"
wnampassword="admin"
wnam_address="172.16.133.12"
if [ ! -f /tmp/token ]; then
	get_token
fi
access_token=`cat /tmp/token`
status=`curl -s -w "%{http_code}" -k -X POST -H "Content-Type: application/json" -H "Authorization: Bearer "$access_token -d "{\"hostname\":\"$1\",\"ARM_IP\":\"$2\",\"ARM_MAC\":\"$3\",\"status\":\"$STATUS\"}" https://$wnam_address/api/2.0/sakura_state`
if [ "$status" -eq 401 ]; then
	get_token
	access_token=`cat /tmp/token`
	curl -s -k -X POST -H "Content-Type: application/json" -H "Authorization: Bearer "$access_token -d "{\"hostname\":\"$1\",\"ARM_IP\":\"$2\",\"ARM_MAC\":\"$3\",\"status\":\"$STATUS\"}" https://$wnam_address/api/2.0/sakura_state
fi

...

Code Block
#!/bin/bash
get_token() {
token=`curl -k -s -X POST -H "Content-Type: application/json" -d '{"username":"'$wnamlogin'","password":"'$wnampassword'"}'  https://$wnam_address/api/2.0/authenticate | jq -r .access_token`
echo $token > /tmp/token
} 

STATUS="1" 
wnamlogin="admin"
wnampassword="admin"
wnam_address="172.16.133.12"
if [ ! -f /tmp/token ]; then
	get_token
fi
access_token=`cat /tmp/token`
status=`curl -s -w "%{http_code}" -k -X POST -H "Content-Type: application/json" -H "Authorization: Bearer "$access_token -d "{\"hostname\":\"$1\",\"ARM_IP\":\"$2\",\"ARM_MAC\":\"$3\",\"status\":\"$STATUS\"}" https://$wnam_address/api/2.0/sakura_state`
if [ "$status" -eq 401 ]; then
	get_token
	access_token=`cat /tmp/token`
	curl -s -k -X POST -H "Content-Type: application/json" -H "Authorization: Bearer "$access_token -d "{\"hostname\":\"$1\",\"ARM_IP\":\"$2\",\"ARM_MAC\":\"$3\",\"status\":\"$STATUS\"}" https://$wnam_address/api/2.0/sakura_state
fi

...

Code Block
#!/bin/bash
get_token() {
token=`curl -k -s -X POST -H "Content-Type: application/json" -d '{"username":"'$wnamlogin'","password":"'$wnampassword'"}'  https://$wnam_address/api/2.0/authenticate | jq -r .access_token`
echo $token > /tmp/token
} 

STATUS="0" 
wnamlogin="admin"
wnampassword="admin"
wnam_address="172.16.133.12"
if [ ! -f /tmp/token ]; then
	get_token
fi
access_token=`cat /tmp/token``
status=`curl -s -w "%{http_code}" -k -X POST -H "Content-Type: application/json" -H "Authorization: Bearer "$access_token -d "{\"hostname\":\"$1\",\"ARM_IP\":\"$2\",\"ARM_MAC\":\"$3\",\"status\":\"$STATUS\"}" https://$wnam_address/api/2.0/sakura_state`
if [ "$status" -eq 401 ]; then
	get_token
	access_token=`cat /tmp/token`
	curl -s -k -X POST -H "Content-Type: application/json" -H "Authorization: Bearer "$access_token -d "{\"hostname\":\"$1\",\"ARM_IP\":\"$2\",\"ARM_MAC\":\"$3\",\"status\":\"$STATUS\"}" https://$wnam_address/api/2.0/sakura_state
fi

...