Hey, I’m trying to get comfortable making scripts. Can anyone help give me perfect my script below? Want to make a script that checks if a host is up and if the host isn’t up it will make sure openvpn is up and running and try to ping again. If the host is up then it will say success prompt for further directions
read “What is your IP?: IP”
ping -c4 $ip
if the output contains “64 bytes from 10.10.10.x: icmp_seq=1 ttl=* time=* ms”
if not echo “Host is not up”
openvpn username.ovpn
I know this is bad but can someone help perfect PLEASE?
It is good to practice. What language do you want to use?
I find iterating each step is good practice - then when one bit is working you can move to the next. As you go you will find the most comfortable technique for you.
For example, in bash you could try:
#!/bin/bash
IP=$1
if ping -c4 $IP | grep -q '64 bytes from 10.10.10'; then
echo "Host is up"
else
echo "Host is not up"
openvpn username.ovpn
fi