0

i have a short bash script which can run a file. When im trying to start this by "x.sh start", there is appearing a warning 'must be connected to a terminal'. How to start this? I tried some configs of chmods. This script is in /usr/local/bin Im now on root, on my Debian 7 vps.

  #!/bin/bash

server_start() {
screen /usr/share/s/x.sh &
}

server_stop() {
killall x.sh
killall xx
}

server_restart() {
server_stop
sleep 1
server_start
}
case "$1" in
'start')
server_start

;;
'stop')
server_stop
;;
'restart')
server_restart
;;
*)
echo "usage $0 start|stop|restart"
esac
  • Note that your script will leave useless screen sessions open for every stop/restart of your service. Using nohup or start-stop-daemon instead would be better. – Gerald Schneider Jan 10 '17 at 11:29
4

screen requires a terminal.

If you want to start a new session in detached mode, then you want to add the -d -m arguments to screen.

1

Your screen call is wrong. Screen require $STY environment variable (-m option prevent it.)

You must use -d (start detached session) and -m (prevent $STY environment variable usage) options instead of & to start a daemon screen session.

Check screen documentation for more info.

0

Start screen in detached mode: screen -dm /usr/share/game/startlss.sh

  • But screening in this patch works fine. I'm trying to start a command "lss.sh start" which is in /usr/local/bin – aio Jan 10 '17 at 11:18
0

Thanks everyone, i added -d -m in lss.sh

server_start() {
screen -d -m /usr/share/game/startlss.sh &

Everything works fine now!

  • If one of the answers solved your problem, accept the answer, this will also mark your question as solved. Don't post someone elses solution as your own. – Gerald Schneider Jan 10 '17 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.