# Simple startup script for TightVNC (error)



## narcotico (Jun 17, 2010)

This is my first script and when I run it from shell with /usr/local/etc/rc.d/vnc onestart/onestop it works perfectly.

But when the system boots up doesn't work. If I run with start I get the next error:

```
Cannot 'start' vnc. Set set_rcvar to YES in /etc/rc.conf or use 'onestart' instead of 'start'
```

I've added vnc_enable="YES" to /etc/rc.conf. I was reading the Handbook about rc scripts but I didn't find the solution. I try changing the line with rcvar with other options that I found in other rc scripts but I get the same problem. Here my script 
	
	



```
#!/bin/sh

. /etc/rc.subr

name="vnc"
vnc_display=":1"
vnc_options="-name Sesion1VNC -depth 16 -geometry 1024x768 -compatiblekbd -fp '/usr/local/lib/X11/fonts/misc,/usr/local/lib/X11/fonts/75dpi/,/usr/local/lib/X11/fonts/100dpi/'"
rcvar='set_rcvar'
start_cmd="${name}_start"
stop_cmd="${name}_stop"
load_rc_config $name
eval "${rcvar}=\${${rcvar}-'NO'}"
vnc_msg=${vnc_msg:-"Iniciando servidor VNC ..."}

vnc_start(){
	echo "$vnc_msg"
	su Carleos -c "PATH=$PATH:/home/Carleos"
	su Carleos -c "vncserver ${vnc_display} ${vnc_options}"
}

vnc_stop () {
	echo -n $"Cerrando servidor VNC ...  "
	su Carleos -c "vncserver -kill :1"
}

run_rc_command "$1"
```


----------



## DutchDaemon (Jun 17, 2010)

I'd expect something like: 
	
	



```
vnc_enable="${vnc_enable-NO}"
```
 in there, and 
	
	



```
rcvar=`set_rcvar`
```
 requires backticks (you appear to use quotes).


----------



## narcotico (Jun 17, 2010)

The error was  for quotes (I'll never think about it). Typical things with new language script/programming...

Now it works perfectly with start/stop/restart/onestart/onestop with my line

```
eval "${rcvar}=\${${rcvar}-'NO'}"
and with yours 
vnc_enable="${vnc_enable-NO}"
```

But it doesn't run at startup with noone of them. I have no idea why.

Thanks.


----------



## DutchDaemon (Jun 17, 2010)

Well, all I can say is study the rc scripts in /usr/local/etc/rc.d/, apply rc(8), and try to emulate them as closely as possible


----------



## narcotico (Jun 19, 2010)

I'll look for it when I have sometime. Meanwhile If somebody knows the solution... Thanks.


----------

