Currently I have below script to check if corresponding services are running on my server or not using some internal logic. Please find code snippet below:
MY_SERVER_ID=X22 //stored somewhere in profile of the servers
if [ "$MY_SERVER_ID" = "X11" -o "$MY_SERVER_ID" = "X22" -o "$MY_SERVER_ID" = "X33" ]
then
##do xx
echo " Service 1 : Running "
fi
if [ "$MY_SERVER_ID" = "X11" -o "$MY_SERVER_ID" = "X22" ]
then
##do xx
echo " Service 2 : Running "
fi
Now as all servers do not run all the services the If conditions become a lot more unreadable/ unnecessary complex. Currently I have 10+ servers and 8+ services where different services run on different servers. Also in future any service can be invoked/ start running on a particular node it wasn't running before in which case I have to go and change the script again.
I understand that in case of any change I definitely have to change the script and update in all the servers however I would like to make the process less painful than it already is.
I can implement something like an array that is defined at the start of the script to point out whether a given service runs on a particular node or not. Something I picked up from this question on stackoverflow.
I know multi dimensional arrays could be easily implemented in C but as I am quite new to shell scripting I would like to know if there is any possibility to make my script more readable and easily editable!!!