mardi 28 janvier 2020

Combine two commands in bash elif (FreeNAS)

I'm really sorry to annoy to you again with my problem but it seems I'm about to finish. My goal is to create a bash-script that checks if a IP-address is still online or a scrub is in progress and if not that my systems shuts down. My script, which is currently in use, looks like this

#!/bin/bash

hosts=(
  10.10.0.100 #Client 1
  10.10.0.101 #Client 2 
  10.10.0.102 #Client 3 
  10.10.0.103 #Client 4
  10.10.0.104 #Client 5
)

for host in "${hosts[@]}"; do
  if ping -c 1 -i 1 "$host" >/dev/null; then
    echo "No Shutdown - At least one PC ($host) is online"
    exit 0
  fi
done

echo "No PC is online - Shutdown"
bash shutdown -p now

I did some research and found the following command, to check if my scrub is in progress

if [ $(zpool status | grep 'scrub in progress') ]; then
    echo "No Shutdown - Scrub in progess"
    exit 0
  fi

But i have problems in combining these two. I want my script to first check the IPs and if they all are offline then check for a scrub before it shuts down the machine. So both if-cases have to be false (ips offline and scrub not in progress) but they should be processed chronological and if the first if-case returns a IP which is online the script should stop.

Maybe somebody can help me?

Aucun commentaire:

Enregistrer un commentaire