Você tem o IP armazenado em i
para poder adicioná-lo ao seu e-mail da seguinte forma:
#!/bin/bash
proxy_targets=( 'http://10.1.1.4:3128' 'http://10.1.1.5:3128' 'http://10.1.1.6:3128' )
failed_hosts=
for i in "${proxy_targets[@]}"
do
exit_code=$(http --check-status --ignore-stdin --timeout=2.5 "--proxy=$i" HEAD www.msftncsi.com/ncsi.txt &> /dev/null; echo $?)
if ((exit_code==0))
then
echo 'OK!'
else
ip=${i#http://} # Removes http:// from variable
ip=${ip%:[0-9]*} # Removes port from the end
case $exit_code in
2) echo 'Request timed out!' | \
mail -s "The following WSA has failed to pass traffic: ${ip}, with the following error: $exit_code" [email protected]
;;
3) echo 'Unexpected HTTP 3xx Redirection!' | \
mail -s "The following WSA has failed to pass traffic: ${ip}, with the following error: $exit_code" [email protected]
;;
4) echo 'HTTP 4xx Client Error!' | \
mail -s "The following WSA has failed to pass traffic: ${ip}, with the following error: $exit_code" [email protected]
;;
5) echo 'HTTP 5xx Server Error!' | \
mail -s "The following WSA has failed to pass traffic: ${ip}, with the following error: $exit_code" [email protected]
;;
6) echo 'Exceeded --max-redirects=<n> redirects!' | \
mail -s "The following WSA has failed to pass traffic: ${ip}, with the following error: $exit_code" [email protected]
;;
*) echo 'Other Error!' | \
mail -s "The following WSA has failed to pass traffic: ${ip}, with the following error: $exit_code" [email protected]
;;
esac
fi
done
- eu coloco
proxy_targets
em uma matriz - Eu citei
--proxy=$i
e removi o extrahttp://
- Estou armazenando o código de saída em uma variável para que seja preservado após a atribuição da variável
- Usando a expansão de parâmetro, tenho
ip
para o endereço atual, removendo a http: // e a porta - Adicionei
ip
eexit_code
ao assunto do e-mail.