Question
Edward Jalbert · Jan 21

Interacting with Iris commands in linux script

We are running HealthShare on Linux Redhat via Azure.

A couple of days ago, the Azure server rebooted. Which we were unaware of. 

Resulting in the Instance being in a downed status.

In the short term I put together a quick script to check the status, if it is down to restart it.

However, before I go down that road, I thought it would be best to inquire if there is a much better and more streamlined solution?

In a nutshell I just want to check and see if the Instance is up or in a state such as  down or hung then start it.

I attached my spaghetti code, full disclosure I am not a scripting guru so I pieced it together with what I know. Google is my friend :-)

 

 

 

#!/bin/bash
## doing some setup get the iris list to grab the status from
echo "--------------Script started at: $(date)-----------------------------" >> /data/temporary/irisStartLog.txt
iris list >> /data/temporary/irisState.txt
sleep 5
## get the state using awk and gerate the irisStatus.txt
awk '/status:/{print $2}' /data/temporary/irisState.txt>>/data/temporary/irisStatus.txt
sleep 5
##create a var get the state of iris from the file created by awk then do a grep to see if the var1 matches var2 
STATUS1=$(head -n 1 /data/temporary/irisStatus.txt)
STATUS2='down,'
Iris='router01'
sleep 5
echo "STATUS1 is $STATUS1"
echo "STATUS2 is $STATUS2"
if grep -q "$STATUS2" <<< "$STATUS1";  then
        echo $(date) "Iris is down commencing restart">>/data/temporary/irisStartLog.txt
iris start $Iris >> irisStartLog.txt
sleep 10
echo "----------------RESTART STATUS --------------------------------------" >> /data/temporary/irisStartLog.txt
iris list >> /data/temporary/irisStartLog.txt
else
        echo $(date) "Iris is not in a down stage at this time" >> /data/temporary/irisStartLog.txt
fi
## do some file cleanup for next run
echo "--------------PREPPING FILE CLEAN UP ------------------------------------" >> /data/temporary/irisStartLog.txt
sleep 15
echo $(date) "removing irisStatus.txt" >> /data/temporary/irisStartLog.txt
rm -f /data/temporary/irisStatus.txt
sleep 2 
echo $(date) "removing irisState.txt" >> /data/temporary/irisStartLog.txt
rm -f /data/temporary/irisState.txt
echo "--------------script completed at: $(date)-----------------------------" >> /data/temporary/irisStartLog.txt

Product version: HealthShare 2020.1
0
0 120
Discussion (2)1
Log in or sign up to continue

Thanks Eduard !!

New there had to be something simpler.