Fab*_*sen 21 linux shell debian gnu-screen
我想在屏幕上以一个带脚本的用户"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 "$1" 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: $0 {start|stop|status|restart}"
exit 1
;;
esac
exit 0
Run Code Online (Sandbox Code Playgroud)
我想在屏幕上连接,但我得到了这个.
Cannot open your terminal '/dev/pts/0' - please check.
Run Code Online (Sandbox Code Playgroud)
我做错什么了吗?
Igo*_*bin 21
要解决此问题,请尝试在启动之前script /dev/null以用户身份运行.suscreen
script -q -c "su $USER -l -c \"screen -m -d -S $NAME $DAEMON start\"" /dev/null
Run Code Online (Sandbox Code Playgroud)
更多信息:
Ner*_*rve 17
发生这种情况是因为您可能已经完成了一个sudo su user_name然后触发了屏幕命令.
有两种方法可以解决这个问题.
script /dev/null用户来获取shell的所有权,user_name然后键入
screen运行此命令以拥有 shell
#script /dev/null
Run Code Online (Sandbox Code Playgroud)
并尝试屏幕
#screen -r < name of the screen >
Run Code Online (Sandbox Code Playgroud)