Results 1 to 3 of 3
Hi
I'm fairly new to bash scripting so please bear with me if i have missed something obvious
I'm trying to make a little script that shows a "up"/"down" status ...
- 02-07-2012 #1Just Joined!
- Join Date
- Feb 2012
- Posts
- 3
printf doesn't align the output to the right when in bash script
Hi
I'm fairly new to bash scripting so please bear with me if i have missed something obvious
I'm trying to make a little script that shows a "up"/"down" status for a handful of applications upon ssh login.
I want the output to show something like this:
apache up
proftpd up
mysql_server up
/dev/sda down
explained, i just want the up/down variable to be aligned to the right side of the screen/terminal.
I tried something like this:
but that just outputs:Code:sda1=`if [ $sda == "standby" ]; then printf "%${COLUMNS}s\n" "\e[0;33mdown\e[m" else printf "%${COLUMNS}s\n" "\e[0;32mup\e[m" fi` echo -e "/dev/sda $sda1"
...without the text alignment.Code:/dev/sda up
If i just write the printf cmd in a bash window, it aligns the output to the right as it should.
It seems like it ignores the alignment when it's being run in in a script?
How can I get the variable-part of each line in the output to be aligned to the right?
- 02-07-2012 #2Just Joined!
- Join Date
- Feb 2012
- Posts
- 3
bump
Any help would be greatly apprecieated!
- 02-07-2012 #3
If you echo $COLUMNS from the script you'll see that it returns nothing, but if you echo it from the console it returns the correct value - hence the reason it doesn't work. Try putting COLUMNS=`tput cols` at the start of your script.


Reply With Quote