I have a debian-based system (Voyage Linux 0.9.1 actually, which is based on debian wheezy) and when I do /etc/init.d/ntp status it returns (for example)

$ /etc/init.d/ntp status
[ ok ] NTP server is running

However, inside a screen session (version 4.01.00devel 2-May-06) the [ ok ] is not shown.

$ screen
$ /etc/init.d/ntp status
NTP server is running

Why is this the case? And how to show it also in the Screen session?

BTW: On another debian server (which also returns xterm-256color when I do echo $TERM), I noticed that /etc/init.d/ntp status does never show the [ ok ], regardless of whether I am in a screen session or not, so it probably is not really a screen issue.


It doensn't require screen. Let's experiment:

TERM=dumb /etc/init.d/ntp status  # no [OK]
/etc/init.d/ntp status | cat      # also no [OK]

This also leaves out the [OK]. Since abviously the output differs based on the TERM setting (dumb and screen drop the [OK]), you can pretend to have a fully featured terminal instead of screen:

TERM=xterm /etc/init.d/ntp status

And it seems to detect as well if it's connected to a terminal. When you pipe the output to another process, the [OK] vanishes.

I assume the reason for this is that due to the use of escape codes for the [OK], there is a check which prevents their use in “unsave” environments. The escape sequences do not really add anything, but they might mess up the output.

The terminal capability check is done in /lib/lsb/init-functions. There's a function called log_use_fancy_output which makes use of tput:

tput The tput utility uses the terminfo database to make the values of terminal-dependent capabilities and information available to the shell

It issues the following two commands:

tput hpa 60
tput setaf 1

From tput: Portable Terminal Control and Bash Prompt HOWTO - Colours and Cursor Movement:

hpa          - Move cursor to column #1
setaf [1-7]  - Set a foreground colour using ANSI escape

In particular log_use_fancy_output checks if it is connected to a terminal. It then checks if TERM is empty or set to dumb and if those two tput operations succeed. If that is successfull, the [OK] is printed, otherwise the [OK] is skipped.

  • Thanks. Indeed, it seem that the outputting of "[ ok ]" or "[FAIL]" in front of daemons is handled by /lib/lsb/init-functions which contains a function log_use_fancy_output() that indeed queries the capabilities of the terminal using tput. It check for something like tput hpa 60 and tput setaf 1 although it is unclear to me from the tput man page what that exactly means... – Rabarberski Aug 7 '13 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.