Linux 屏幕无法打开您的终端 '/dev/pts/0' - 请检查

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21328140/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:54:25  来源:igfitidea点击:

screen Cannot open your terminal '/dev/pts/0' - please check

linuxshelldebiangnu-screen

提问by Fabian Harmsen

I want to start a program in a screen as the user "XYZ" with a script. This is my script in short form:

我想在屏幕中以用户“XYZ”的身份使用脚本启动一个程序。这是我的简短脚本:

# replace <newuser> with the user you wish to run teamspeak 3 with.
USER="teamspeak"
# Do not change this path
PATH=/bin:/usr/bin:/sbin:/usr/sbin
# The path to the teamspeak 3 server/scripts . example = /home/teamspeak3/teamspeak3-server
DIR=/home/teamspeak/voiceserver/teamspeak3
DAEMON=$DIR/ts3server_startscript.sh
# Change all PARAMS to your needs. I required the ini so teamspeak used MySQL
PARAMS="inifile=ts3server.ini"
#Name = The screen will be named from this.
NAME=teamspeak3
DESC="Teamspeak Server 3"


case "" in
start)
echo "Starting $DESC"
script -q -c "su $USER -l -c \"screen -m -d -S $NAME $DAEMON start\"" /dev/null
;;
stop)
su $USER -l -c "screen -S $NAME  -X quit "
    echo " ... done. $DESC Stopped."
;;
restart)
su $USER -l -c "screen -S $NAME  -X quit "
    echo " Closed Process, Restarting"
script -q -c "su $USER -l -c \"screen -m -d -S $NAME $DAEMON start\"" /dev/null
echo " ... done. $DESC Restarted"
;;
status)
# Check whether there's a "Team Speak 3" process
ps aux | grep -v grep | grep ts3server_ > /dev/null
CHECK=$?
[ $CHECK -eq 0 ] && echo "$DESC is UP" || echo "$DESC is DOWN"
;;
*)
echo "Usage: 
Cannot open your terminal '/dev/pts/0' - please check.
{start|stop|status|restart}" exit 1 ;; esac exit 0

I want connect in the screen, but I got this.

我想在屏幕上连接,但我得到了这个。

script -q -c "su $USER -l -c \"screen -m -d -S $NAME $DAEMON start\"" /dev/null

Did I do something wrong?

我做错什么了吗?

采纳答案by Nerrve

This happens because you may have done a sudo su user_nameand then fired the screen command.

发生这种情况是因为您可能已经执行了 asudo su user_name然后触发了 screen 命令。

There are 2 ways to fix this.

有 2 种方法可以解决此问题。

  1. Login directly to "user_name" via ssh.
  2. Take ownership of the shell by typing script /dev/nullas the user user_nameand then type screen
  1. 通过 ssh 直接登录到“user_name”。
  2. 通过script /dev/null以用户身份键入user_name然后键入 来获取 shell 的所有权screen

回答by Igor Chubin

To solve the problem try running script /dev/nullas the user you suto before launching screen.

要解决此问题,请在启动前尝试script /dev/null以您的用户身份运行。suscreen

#script /dev/null  

More on it:

更多相关信息:

回答by Javeed Shakeel

Run this command to own the shell

运行此命令以拥有 shell

#screen -r < name of the screen >

and try Screen

并尝试屏幕

sscreen(){
    script -q -c "screen $*" /dev/null;
}

回答by Fabian Harmsen

here is the way i found. i cann't use screenfrom rc.localor better if i want to use it i would need root. I don't want to use root. My way is now to use crontab -ethis is working.

这是我找到的方法。我不能screen从 rc.local使用或更好,如果我想使用它,我需要 root。我不想使用root。我现在的方法是使用crontab -e它。

回答by Blaf

Inspired by both endorsed answers here I added the following function to my .bashrc:

受到这里两个认可答案的启发,我将以下功能添加到我的.bashrc

##代码##

Now I just use sscreeninstead of screenand never have to think about the issue again.

现在我只是使用sscreen而不是,screen再也不用考虑这个问题了。