Need help making scripts!

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:



if ping -c4 $IP | grep -q '64 bytes from 10.10.10'; then
    echo "Host is up"
    echo "Host is not up"
    openvpn username.ovpn

then invoke it with IPADDR

Thank you! I am testing it out now. Will let you know of kinks.

So instead of me having to type the IP every time. How would I sweep 10.10.10.* and have it return which hosts are up if any?

Well, really you could try nmap -T4 but it gets a bit more complex now.