STiGYFishh
STiGYFishh

Reputation: 788

tmux open terminal failed: not a terminal

I have a shell script that is enabled as service to start multiple shell scripts e.g.

service started script -> script1, script2 ,script3 

script1 should open a program in a tmux window, and it does work just fine if I manually start the script via ./script1.sh, however when started at boot via the service started script it does not with the above error:

open terminal failed: not a terminal

Why is this happening?

Upvotes: 49

Views: 47847

Answers (3)

Selmison Miranda
Selmison Miranda

Reputation: 473

If you use p10k as a zsh theme, as mentioned here, you should put this stanza in the top of .zsrc:

if [ -z "$TMUX" ]; then
  exec tmux new-session -A -s workspace
fi

Upvotes: 6

7hibault
7hibault

Reputation: 2459

I think the issue is that the service does not have an associated tty. A workaround I've found is to change your tmux call in your script to

tmux new-session -s username -d

(username a user for whom the service was started)

Upvotes: 20

lorenzog
lorenzog

Reputation: 3611

There is an answer already here, but this link I think summarises it better. In a nutshell, use the -t flag:

ssh -t host tmux attach

If you want to set it into your .ssh/config file, look in the ssh_config manpage for the RequestTTY option:

 RequestTTY
         Specifies whether to request a pseudo-tty for the session.  The
         argument may be one of: ``no'' (never request a TTY), ``yes''
         (always request a TTY when standard input is a TTY), ``force''
         (always request a TTY) or ``auto'' (request a TTY when opening a
         login session).  This option mirrors the -t and -T flags for
         ssh(1).

Upvotes: 59

Related Questions