Reputation: 59
I have a shell script in server A and I have a shell script in server B. My logic is written like shell script in A gets executed and it calls a shell script in server B and executes it. I am able to get the desired result when A executes B, but getting an error also along with the result. Error Message:
tput: No value for $TERM and no -T specified
I am using the following lines for getting output in color;
RED=`tput setaf 1`
GREEN=`tput setaf 2`
YELLOW=`tput setaf 3`
BLUE=`tput setaf 6`
BOLD=`tput bold`
RESET=`tput sgr0`
These lines are available in the shell script in both A and B. When I execute the shell script in B by logging into server B, the desired output comes along with the color. When I call the shell script from A and execute it, I am getting desired result plus the error message which I mentioned above.
Can you help in this regard?
FYI, I checked "echo $TERM"
and output is 'xterm'
in both the servers.
Not sure where I am going wrong.
Upvotes: 2
Views: 4452
Reputation: 11
My solution:
# when $TERM is empty (non-interactive shell), then expand tput with '-T xterm-256color'
[[ ${TERM}=="" ]] && TPUTTERM='-T xterm-256color' \
|| TPUTTERM=''
declare -r RES='tput${TPUTTERM} sgr0' REV='tput${TPUTTERM} rev'
declare -r fRD='tput${TPUTTERM} setaf 1' bRD='tput${TPUTTERM} setab 1'
declare -r fGN='tput${TPUTTERM} setaf 2' bGN='tput${TPUTTERM} setab 2'
...
echo ${fRD}" RED Message: ${REV} This message is RED REVERSE. "${RES}
echo ${fGN}" GREEN Message: ${REV} This message is GREEN REVERSE. "${RES}
...
This way it makes no sense if there's an interactive or a non-interactive shell - tput still works fine.
Upvotes: 1
Reputation: 59
I am able to fix the issue successfully now.
ssh <Server B> "TERM=xterm" <script in ServerB>
The desired output came back to ServerA with colors.
Upvotes: 0
Reputation: 1
We supposed that the shell or environment setting are different in two servers, if possible, you can past output of next commands from the two servers.
ps
This command helps us understand what kind of shell we are using.
env
This command helps us know the environment.
Upvotes: 0
Reputation: 189809
$TERM
will be unset when you log in via a script. Bypass the color-coding in this scenario, or hard-code an option to tput
. (I would strongly suggest the former.)
RED=; GREEN=; YELLOW=; BLUE=; BOLD=; RESET=;
case ${TERM} in
'') ;;
*)
RED=`tput setaf 1`
GREEN=`tput setaf 2`
YELLOW=`tput setaf 3`
BLUE=`tput setaf 6`
BOLD=`tput bold`
RESET=`tput sgr0`;;
esac
Upvotes: 0