-1

I use Ubuntu 14.04.4 LTS and installed vnc4server. The basic script starting vncdesktops is under /etc/init.d/vncserver which is a bash script. This works fine for all users specified in /etc/vncserver/vncservers.conf with their arguments. But when a user is using csh instead of bash, the vncserver command doesn't work because of a syntax error in the vncserver script. The error occurs in the start() function which I show here.

start() {
 . /lib/lsb/init-functions
 REQ_USER=$2
 echo -n $"Starting $prog: "
 ulimit -S -c 0 >/dev/null 2>&1
 RETVAL=0
 for display in ${VNCSERVERS}
 do
 export USER="${display##*:}"
 if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
 echo -n "${display} "
 unset BASH_ENV ENV
 DISP="${display%%:*}"
 export VNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
 su ${USER} -c "cd ~${USER} && [ -f .vnc/passwd ] && vncserver :${DISP} ${VNCUSERARGS}"
 fi
 done
}

When I give the command 'sudo service vncserver restart' the vncserver script runs and give me this error for a user using csh.

Starting VNC server: 8:test1 [: No match.

user 'test1' is using csh and its display number is 8. I can see this error is coming from the line

su ${USER} -c "cd ~${USER} && [ -f .vnc/passwd ] && vncserver :${DISP} ${VNCUSERARGS}"

and I understand what it's doing but I don't know why the bracket condition is giving me this error and that only for a user using csh. Can anyone give me a clue?

Chan Kim
  • 5,177
  • 12
  • 57
  • 112
  • does "cd ~${USER}" expand as expected in csh? you may wish to test this, as the '[ -f .vnc/passwd ]' is looking for the file ${users-home-dir}/.vnc/passwd and it is not found. Conversly, does the .vnc/passwd file actually exist in test1's home directory? – Cwissy May 13 '16 at 15:20
  • The ${USER} expands as test1 as I expect and .vnc/passwd exists in ~test1. BTW the script itself is a bash script. – Chan Kim May 13 '16 at 15:31
  • I installed tcsh and made a link to tcsh for csh, now the problem is gone. I don't know why.. – Chan Kim May 13 '16 at 16:06

1 Answers1

0

I don't know exactly why, but I found my /bin/csh was linked as below.

/bin/csh -> /etc/alternatives/csh  

So I installed tcsh (apt-get install tcsh) and made the link like this.

/bin/csh -> /bin/tcsh  

Then the problem is gone! The su command and the command executed by -c option is being processed in the su'ed user's shell which was /etc/alternatives/csh which probably could not handle the [ -f ] condition. and I gues the /etc/alternatives/csh is a kind of default csh linked to when there is no real full fledged csh(like tcsh).

Chan Kim
  • 5,177
  • 12
  • 57
  • 112