If you are a SAS administrator managing an environment on UNIX or z/OS, you must use the sas.servers script on a regular basis. As you know, one of its uses is to display the current status of all servers. Is the output accurate? Absolutely. Is it easy to read? Relatively. Is it visually attractive? Not so much.
Human beings are visual creatures. Conventional wisdom says that a picture speaks a thousand words. However, I am not using images to improve the output, but another powerful tool: color. According to this Xerox paper, color captures attention and enhances productivity. It can improve search time, reduce errors, and increase comprehension. As a result, this blog post provides the steps for applying color and an easy-to-read layout to make the sas.servers script look cute and even fun!
Preliminary Steps
Before we begin, it is important to give you some recommendations:
- Stop all SAS services.
- Backup the files: sas.servers, sas.servers.mid and sas.servers.pre
- Apply these changes to a Development or Testing environment.
As a matter of fact, I consider steps 1 and 3 as optional. This script is only used by the SAS platform to start/stop/restart or check the status of the servers. Moreover, if you follow all steps carefully, you can apply these changes safely in a Production environment. In contrast, step 2 is relevant; it is always a good practice to backup essential files before modifying them. In case you need to rollback, you can restore them easily and quickly.
Things to Consider
The About the sas.servers Script section from the SAS 9.4 Intelligence Platform: System Administration Guide provides a caution message: "You should not directly update the sas.servers script." In our case, the type of customization we are about to perform requires a manual update. Don't worry, your script is in good hands.
Furthermore, if you ever need to update the sas.servers script because you want to add/remove a server, you have to run the generate_boot_scripts.sh
script to regenerate this file. After doing so, you can lose all the changes made in this post. Keep this in mind, so you can backup the current files before attempting this task.
Easy-to-read Layout
Let's jump into the details. First of all, let's define the new layout of the desired output. Grab your favorite text editor. Go to your /SASCONFIG/Lev1/
directory and run a regular status command as the sas user. Assuming you followed the preliminary steps and depending on the products installed and the number of SASServers deployed, you should get a similar output:
./sas.servers status SAS servers status: SAS Web Infrastructure Data Server is NOT up SAS Metadata Server 1 is NOT up SAS Object Spawner 1 is NOT up SAS DIP Job Runner 1 is NOT up SAS Information Retrieval Studio Server is NOT up SAS JMS Broker is NOT up SAS Cache Locator Service ins_41415 is NOT up SAS Web Server is NOT up SAS Web App Server SASServer1_1 is NOT up SAS Environment Manager is NOT up SAS Environment Manager Agent is NOT up |
Copy that output, except the first line, and paste it into your text editor. Here you can modify the output according to your taste. What I did was to identify the longest line, which is SAS Information Retrieval Studio Server, then I added four spaces to the right and substituted the legend is NOT up for [DOWN]. Likewise, I applied these changes to the rest of the servers, removed the instance number, and kept them all aligned:
SAS Web Infrastructure Data Server [DOWN] SAS Metadata Server [DOWN] SAS Object Spawner [DOWN] SAS DIP Job Runner [DOWN] SAS Information Retrieval Studio Server [DOWN] SAS JMS Broker [DOWN] SAS Cache Locator Service ins_41415 [DOWN] SAS Web Server [DOWN] SAS Web App Server SASServer1_1 [DOWN] SAS Environment Manager [DOWN] SAS Environment Manager Agent [DOWN] |
I chose the pair [ UP ]/[DOWN] to reflect the status because I wanted the look and feel from CentOS 6 boot process. If you are/were a CentOS 6 user, you can remember that the services display the legends: [ OK ] or [FAILED] when booting. You are free to use other alternatives such as ACTIVE/INACTIVE or perhaps RUNNING/STOPPED with or without brackets. Now that the layout is finished, let's move on to the color department.
All You Need Is Color
The fun finally arrived. Let's integrate the layout into our three scripts and add the main ingredient: color!
Again, I am assuming at this stage that you already backed up the files: sas.servers, sas.servers.mid, and sas.servers.pre. Next, open the sas.servers file with your vi editor and add this code anywhere at the top, below the block of comments:
#***** # Custom Colors for status command # RED for [DOWN] # GREEN for [ UP ] # NC for No Color #***** RED='\e[31m' GREEN='\e[32m' NC='\e[0m' |
These lines create three variables with three different color codes: a RED variable with code 31, a GREEN variable with code 32, and a NC variable with the default color code. The definition of these variables is optional but recommended, since they help you debug problems or change colors more easily. If you prefer to use different colors or attributes, you can play with the codes as shown in Bash tips: Colors and formatting.
If these escape codes don’t work in your environment, then you can use the tput
command as follows:
RED=`tput setaf 1` GREEN=`tput setaf 2` NC=`tput sgr0` |
Considering that the sas.servers script does not contain all servers, you have to add the same code to sas.servers.mid and sas.servers.pre files.
First Example
Now that we have defined the three variables in all the necessary files, let's use them. I'll show you how to apply them to a couple of servers, and then you can replicate it to the rest. The first one is the SAS Metadata Server. Open the sas.servers script again and find these lines:
# SAS Metadata Server SASMETA_WONT_START_OTHERS="The remaining SAS servers will NOT be started as a result." SASMETA1_IS_UP="SAS Metadata Server 1 is UP" SASMETA2_IS_UP="SAS Metadata Server 2 is UP" SASMETA3_IS_UP="SAS Metadata Server 3 is UP" SASMETA4_IS_UP="SAS Metadata Server 4 is UP" SASMETA5_IS_UP="SAS Metadata Server 5 is UP" SASMETA1_IS_DOWN="SAS Metadata Server 1 is NOT up" SASMETA2_IS_DOWN="SAS Metadata Server 2 is NOT up" SASMETA3_IS_DOWN="SAS Metadata Server 3 is NOT up" SASMETA4_IS_DOWN="SAS Metadata Server 4 is NOT up" SASMETA5_IS_DOWN="SAS Metadata Server 5 is NOT up" |
Since I have a single Metadata Server instance, the only meaningful variables are SASMETA1_IS_UP and SASMETA1_IS_DOWN. Delete their values, copy the correct string from your text editor, and paste it in both variables. Fix them accordingly:
SASMETA1_IS_UP="SAS Metadata Server [ UP ]" #more instances SASMETA1_IS_DOWN="SAS Metadata Server [DOWN]" #more instances |
The final touch is to give color to our script. Use the GREEN and RED variables for the UP/DOWN statuses. It is important to include the NC variable at the end to remove all attributes:
SASMETA1_IS_UP="SAS Metadata Server [ ${GREEN}UP${NC} ]" #more instances SASMETA1_IS_DOWN="SAS Metadata Server [${RED}DOWN${NC}]" #more instances |
Second Example
The process is the same for all the servers defined in the sas.servers script. For the other two scripts it is a little different, but still quite easy. I am going to use the SAS Web Infrastructure Data Server as the second example. Open the sas.servers.pre script and look for the server_status()
function. Pay attention to these lines:
if [ $? -eq 0 ]; then # Server is already running echo "SAS Web Infrastructure Data Server is UP" else echo "SAS Web Infrastructure Data Server is NOT up" fi } else echo "SAS Web Infrastructure Data Server is NOT up" |
A subtle difference from the previous example is the echo
command. In the sas.servers script, there is a logmsg()
function that uses the echo -e
command behind the scenes. In this case, we have to explicitly add the -e
option to enable the interpretation of backslash escapes. Let's also integrate the color and layout:
echo -e "SAS Web Infrastructure Data Server [ ${GREEN}UP${NC} ]" else echo -e "SAS Web Infrastructure Data Server [${RED}DOWN${NC}]" fi } else echo -e "SAS Web Infrastructure Data Server [${RED}DOWN${NC}]" |
At this point, with the above examples, you should have a solid idea about the required changes to accomplish our goal. Now it is your turn to apply them to the rest of the servers.
Finished Product
If you followed this article in detail and performed the steps in all the required servers, your output should resemble mine:
Get the green light by running the start command:
Final Thoughts
I am a visual person with a curious mind. One of the things I like is to customize the tools I use the most, so I decided to make the sas.servers script output a little more attractive to my eyes. I hope you liked the result. If you are still not sure whether to implement this idea or not, let's suppose there are some problems with a couple of servers in your environment and they stop running. Which output would you rather look at? Which one is easier to spot an issue? Let me know your thoughts in the comments below, or even better you can share your creative outputs!
19 Comments
Sri
Instead of using the escapes, have you tried the tput options listed above?
RED=`tput setaf 1`
GREEN=`tput setaf 2`
NC=`tput sgr0`
-or-
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
NC=$(tput sgr0)
Sri
Have you tried the tput option instead of the escape:
RED=`tput setaf 1`
GREEN=`tput setaf 2`
NC=`tput sgr0`
Cliff
When I tried to implement this I got this
SAS servers status:
SAS OLAP Server 1 [\e[32mUP\e[0m]
SAS Object Spawner 1 [\e[32mUP\e[0m]
SAS Share Server 1 [\e[32mUP\e[0m]
SAS CONNECT Spawner 1 [\e[32mUP\e[0m]
SAS DIP Job Runner 1 [\e[32mUP\e[0m]
I think the server fails to recognize the colors. Did I miss anything ? can you help me on this
Hi Roberto,
First of all: great tip and IMHO a much clearer way to see if a server is up or down.
The only thing I am still struggling with is the alignment of the [UP] and [DOWN] text for the SAS Web App servers.
In my installation, SASServer1_1, SASServer2_1, SASServer12_1 and SASServer13_1 are started.
In the sas.servers.mid script the 'name' of the SAS Web App server is indicated with a parameter being $SASWEBAPPINSTANCE
Since the text of the latter two is one longer than the first two allignment goes wrong.
Do you have a suggenstion how this could be fixed?
Kind regards,
--Resa
Hello,
I got around this by using an if...then...else statement around the echo statements that would count the characters in the variable and then echo differently if the variable had 13 characters. The code I used is below - it doesn't keep the spaces and formatting when I reply here, but you can figure it out I think
# Server is already running
if [ ${#SASWEBAPPINSTANCE} = 13 ]; then #added line
echo -e "SAS Web App Server $SASWEBAPPINSTANCE [ ${GREEN}UP${NC} ]" #added line with one less space in the echo
else # added line
echo -e "SAS Web App Server $SASWEBAPPINSTANCE [ ${GREEN}UP${NC} ]"
fi # added line
else
if [ ${#SASWEBAPPINSTANCE} = 13 ]; then #added line
echo -e "SAS Web App Server $SASWEBAPPINSTANCE [ ${RED}DOWN${NC} ]" #added line with one less space in the echo
else # added line
echo -e "SAS Web App Server $SASWEBAPPINSTANCE [${RED}DOWN${NC}]"
fi # added line
fi
} # if PID
else
if [ ${#SASWEBAPPINSTANCE} = 13 ]; then #added line
echo -e "SAS Web App Server $SASWEBAPPINSTANCE [ ${RED}DOWN${NC} ]" #added line with one less space in the echo
else # added line
echo -e "SAS Web App Server $SASWEBAPPINSTANCE [${RED}DOWN${NC}]"
fi # added line
Nice job Roberto. These scripts are valuable but have been lacking some TLC lately of the sort you provide here.
There is one thing about changing sas.servers and sas.servers.mid that I feel I have to warn about. Some updates like adding, disabling or enabling servers or an in-place update to a new maintenance level will regenerate the scripts and undo the changes you propose here. In fact the
generate_boot_scripts.sh
gets executed. Would it be feasible to apply the changes to the template files? The templates are in{LEVDIR}/Utilities/script_templates
. From the looks of it it would only involve changing the filemessages_en.txt
. So whenevergenerate_boot_scripts.sh
is run the changes will survive that.Thanks,
- Jan.
Jan, thank you for your comment. Considering the admin tasks any SAS administrator may need to perform in the future, I decided to include a warning in the Things to Consider section about the consequences of running the
generate_boot_scripts.sh
script. I have not tested using those templates but sounds like a reasonable idea. If you are able to do some testing, please share your results with the community!The templates are the better solution if you wish to have your changes retained if the generate_boot_scripts.sh is run. The template directory contains many different templates for many different needs, but to accomplish what you have suggested above on a Linux OS system installed with the EN language, the four files that require edits are
messages_en.txt
sas.servers.mainlog
sas.servers.mid.template
sas.servers.pre.template
The sas.servers.mainlong is the place you would want to edit the logmsg() function to retain the echo -e across script regeneration. Also, don't forget to put the color definition in each of the templates otherwise the generated scripts won't know about the color variables.
Actually - as I look deeper, there are multiple other templates you would need to edit to make sure you were hitting all of your SAS services. Just search each template for the "is UP" string and you will see what is in which file.
oops, please replace the SASCONN1_ISUP line as follows:
SASCONN1_IS_UP="SAS CONNECT Spawner 1 [${green}UP${reset}]"
Thanks,
Jesus
Hi Roberto,
Neither of the highlighting\coloring approaches provided here worked for me on RHEL 6.7, however this does ;
red=$(tput setaf 1)
green=$(tput setaf 2)
reset=$(tput sgr0)
SASCONN1_IS_UP="SAS CONNECT Spawner 1 [${green}UP$(tput sgr0)]"
Also, I have a script that runs sas.servers on all the servers from a single remote machine using passwordless SSH.
The color doesn't transfer over to the remote server when displaying the output. Have you tested this scenario?
Thanks,
Jesus
Hi Jesus,
I didn't test a remote scenario since I only have SAS on a single server. Now that you mention it, I gave it a try and the colors display correctly in both cases:
a) Remote command
b) Bash script
Let me know your thoughts.
-Roberto
Hi Guys,
Unfortunately that modifcation doesn't work for me. Instead of color, i got the the color codes printed in the output.
But by following Nik's suggestion to go for tput, i was able to change the colors using the following parameters.
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
SASMETA1_IS_UP="SAS Metadata Server 1 [ ${green}UP${reset} ]"
SASMETA1_IS_DOWN="SAS Metadata Server 1 [ ${green}DOWN${reset} ]"
correct the last line as 'red'
SASMETA1_IS_DOWN="SAS Metadata Server 1 [ ${red}DOWN${reset} ]"
Hi Jickson, what operating system are you using? I tested all commands on a Linux machine, since the majority of our customers, at least in Latin America, run SAS on Linux. Yes, Nik's approach works in other UNIX-based systems.
Also, you can run this command to know if your terminal supports 256 colors and the color number, in my case my terminal only supports 8 colors:
( x=`tput op` y=`printf %$((${COLUMNS}-6))s`;for i in {0..256};do o=00$i;echo -e ${o:${#o}-3:3} `tput setaf $i;tput setab $i`${y// /=}$x;done; )
-Roberto
Hey Roberto, this is great! You should have a look at the tput command - it'll consider what terminal type you're using and generate the appropriate terminal escape codes for colour etc. on the fly, which should increase compatibility a bit when it comes to things like AIX terminals etc.
Check out an example of it here: https://github.com/Boemska/worktop/blob/master/worktop#L40
Nik
Hi Nik, thanks for your valuable suggestion. By the way, you coded an awesome script, I'll test it out with your permission.
-Roberto
Personally I prefer your custom status output with the statuses aligned and with red and green colours. I wonder what a colour blind person would see though?
That's a really good question, Michelle. I read this condition only affects 8% of men and 0.5% of women on average (according to the Colour Blind Awareness website). I'm sorry I did not test this idea on that population because I do not have any friends or family with that condition, but even without the colors, I still think that the proposed layout will be helpful. Anyway, I'll try to find someone 😉