1

I have a very simple script that echoes some stuff then starts a VNC Server. It works fine when I run it on the command line but when it runs on startup it gives some strange results. Here is my script

### BEGIN INIT INFO
# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.
### END INIT INFO

#! /bin/sh
# /etc/init.d/vncboot

USER=root
HOME=/root

export USER HOME

case "$1" in
 start)
  echo -e "[ \e[32mok\e[39m ] Starting VNC Server"
  #Insert your favoured settings for a VNC session
  /usr/bin/vncserver :1 -geometry 1920x1080 -depth 24 &> /dev/null
  ;;

 stop)
  echo -e "[ \e[32mok\e[39m ] Stopping VNC Server"
 /usr/bin/vncserver -kill :1 &> /dev/null
 ;;

 *)
  echo "Usage: /etc/init.d/vncboot {start|stop}"
  exit 1
  ;;
esac

exit 0

First of the echo doesn't run right. It gives me this,

-e [ \e[32mok\e[39m ] Starting VNC Server

Then the VNC Server works fine but it still displays the ouptut even though I don't wan't it to. This is the same for both start) and stop) cases.

  • What actual shell is /bin/sh? not all shells support the &> redirection syntax, you may need to use POSIX-compatible > /dev/null 2>&1 instead. Similarly, the shell may be invoking a built-in echo which might not support -e and/or the ANSI escapes (although /bin/echo might). – steeldriver Feb 14 '15 at 14:52
  • works perfectly in "bash". – bluefoggy Feb 14 '15 at 14:55
  • steeldriver thank you it works like a charm!!! – likelukeyo Feb 14 '15 at 15:18
  • Please read the help tour. On this site answered are accepted and never marked with [SOLVED] and thanks and other chit-chat should be avoided in questions and answers. – Anthon Feb 14 '15 at 16:38
1

Thanks to @steeldriver I figured it out. I changed,

command &> /dev/null

to,

command > /dev/null 2>&1

I also changed,

echo

to,

/bin/echo

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.