Problem with using colors in bash script
I'm trying to make a script that prints a list of services and drives etc and their status.
It outputs various services status in color. Fx. "up" colored green if running and "down" colored red if not running. That works perfectly when using echo - but when I'm using printf, it just shows everything in green - even if it's down. I checked the scripts colorcodes but can't find the error. See attached file. The relevant code: Code:
chkapache2=`ps aux | grep apache2 | grep -v "grep apache2" | wc -l` |
The first usage of variables chkapace, chksamba is prefixed with $, the second isn't (check your if-statements).
And in test, it is not ==, use either = (strings) or -eq (numbers) |
Quote:
I have another question about alignment I hope you can answer as well :-) Right now the script left-aligns the first column and right-aligns the second and third. I would like it to left-align the second/mid column - but how to do that? |
Quote:
COLS_PER_COL=15 The variable would be set to "" or "0" if not declared . test should work with '==' because it would also work with '!=' . '==' and '=' spits fewer error messages than '-eq','-lt','-ge',... because they can match a char or string also . it is also advisable to double quote the first value in a test comparison for a number in case the string is empty . Code:
a= |
> Right now the script left-aligns the first column and right-aligns the second and third. I would like it to left-align the second/mid column - but how to do that?
An example might help: Code:
$ printf "%-15s %-15s %-15s\n" "Left_1" "Left_2" "Left_3" Code:
WIDTH=15 |
All times are GMT -5. The time now is 11:13 PM. |