-1

I have a nodetimecheck.sh file on a server which has a command like this

echo
tput setaf 2; echo -n " What is my node's local time: "; tput setaf 7; date

When I login to my server with SSH and execute ./nodetimecheck.sh it displays properly.

However, if I try to execute the command from my local machine via ssh like this

ssh -i ~/.ssh/privkey username@serverip ./nodetimecheck.sh

It does display the time, but there is a nagging message

tput: No value for $TERM and no -T specified

Local machine running Ubuntu 18.04 LTS Remote server on GCP running Ubuntu 18.04 LTS

Mirror Mirage
  • 1,287
  • 1
  • 8
  • 7

2 Answers2

0

Found the solution as follows. Supply the TERM=xterm as part of the ssh command

ssh -i ~/.ssh/privkey username@serverip TERM=xterm ./nodetimecheck.sh
Mirror Mirage
  • 1,287
  • 1
  • 8
  • 7
  • This would only "work" if you are connecting from a terminal where `TERM` is not set, and has no effect on the other end of the connection. – Thomas Dickey Aug 27 '23 at 21:15
0

You're trying to execute tput command when there's no TTY available.

A real solution would check whether the command is executed in a real terminal:

#!/bin/sh
# a wrapper that checks whether TTY is available
t_put () {
  tty -s && tput "$@"
}
echo 
t_put setaf 2; echo -n " What is my node's local time: "; t_put setaf 7; date
Tombart
  • 30,520
  • 16
  • 123
  • 136