I need to create a batch sript to check if Internet is responding. If is responding then do nothing, but if no responding then post usernname and password to a URL. Bellow and example that I want to do, I know that the script is wrong and is for this rason that I am asking for help.
#!/bin/sh if ping -c 1 8.8.8.8 &> /dev/null then do={/tool fetch http-method=post http-data="username=myuser&&password=mypass" url="https://secure.etecsa.net:8443//LoginServlet" } else echo 0 fi
You can use curl to post your message:
#!/bin/bash
######################################################################
# Script Configuration
######################################################################
TARGET_URL="https://secure.etecsa.net:8443/LoginServlet"
# Set the internet server to be verified (Change this as needed)
VERIFICATION_SERVER="8.8.8.8"
# Verification Timeout (seconds)
VERIFICATION_TIMEOUT_IN_SECONDS=1
# User Data
data="username=myuser&&password=mypass"
# Checks if internet is reachable
ping -c 1 -W ${VERIFICATION_TIMEOUT_IN_SECONDS} ${VERIFICATION_SERVER} &> /dev/null
if [[ $? -ne 0 ]]; then
# Internet not detected,
# post username and password to URL
curl --insecure -X POST ${TARGET_URL} -d "${data}"
else
# Internet active
echo "Internet is active."
fi