LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   VNC automatic startup script (http://www.linuxquestions.org/questions/linux-networking-3/vnc-automatic-startup-script-44160/)

Gianni 02-05-2003 04:36 AM

VNC automatic startup script
 
Hi all

I am using SUSE 7.2 and was wondering if anyone could help with a script to start vncserver automatically when the machie is booted / rebooted ?

I have tried one but it doesn't seem to work. Also most of the references are to Red HAt and some of the files they talk about are not in the same location.

thanks
gianni
ps. Yep, I am only beginning to use Linux.

antken 02-07-2003 10:08 AM

hi,


i had this problem a couple of months ago, basically you need to add it to your start up, or init scripts as they are some times called

to do this:

find out what run level your computer starts in

you can do this by entering the command:

cat /etc/inittab |grep default

it will then return a few lines the last one it returns should be something like id:X:initdefault

the X represents a number, this number is the runlevel that your computer start in

next:

jump into the initscripts directory for that run level
todo this type :
cd /etc/rcX.d
( where X is the default run level )

in this directory are the 'init scripts' that the system runs at startup they generally named in this fashion
S**program ( where ** is the number order in which it is loaded ( 0 is first then 1 etc ) ) S means start and K means kill ( or to stop the process )

then use vi or your favorite text editing program to create the start up script
for example: vi S94vncserver

now you need to start creating your shell script
to start the file, on the very first line you need the shebang, this shebang is a hint to the system of what program is needed to process the script. a shebang line looks like this:
#!/bin/sh

the #! is the start of the shebang and sets the ball rolling, the '/bin/sh' gives refrence to sh, a command interpriter that most linux boxes have.

now you need to put your script together you can use normal command line options in this file ( as far as i know )
for example:

Code:

#!/bin/sh
#
# Description: Starts Vnc server at startup


echo "Starting VNCServer:"
/path/to/vnc/server && echo "Success"


the above is just basic script, its probably best if you look up using google 'linux shell scripts' and learning it properly. Plus look at some of your existing startup scripts and you will learn how to do one where you can type vncserver start or vncserver stop

dont forget to set the exeecute permission on the file you create or you may have problems

i would recomend starting vncserver last this gives the system the chance to load any program dependancys, like vnc needs network to be started first in order to function

i hope this helps

:)

note: if there is any one else out there at can do this in a better way i really would like to hear it please

baldy3105 02-07-2003 11:41 AM

There was info on this on the VNC homepage. You can start it using inetd apparently, also there is some sort of RC script info here - http://www.mpthrill.com/vncrc

Gianni 02-10-2003 05:41 AM

I get syntax error messages when the system is rebooted and it runs that script..


Quote:

Originally posted by baldy3105
There was info on this on the VNC homepage. You can start it using inetd apparently, also there is some sort of RC script info here - http://www.mpthrill.com/vncrc

Gianni 02-10-2003 05:42 AM

THANKS ! will try it out

Quote:

Originally posted by antken
hi,


i had this problem a couple of months ago, basically you need to add it to your start up, or init scripts as they are some times called

to do this:

find out what run level your computer starts in

you can do this by entering the command:

cat /etc/inittab |grep default

it will then return a few lines the last one it returns should be something like id:X:initdefault

the X represents a number, this number is the runlevel that your computer start in

next:

jump into the initscripts directory for that run level
todo this type :
cd /etc/rcX.d
( where X is the default run level )

in this directory are the 'init scripts' that the system runs at startup they generally named in this fashion
S**program ( where ** is the number order in which it is loaded ( 0 is first then 1 etc ) ) S means start and K means kill ( or to stop the process )

then use vi or your favorite text editing program to create the start up script
for example: vi S94vncserver

now you need to start creating your shell script
to start the file, on the very first line you need the shebang, this shebang is a hint to the system of what program is needed to process the script. a shebang line looks like this:
#!/bin/sh

the #! is the start of the shebang and sets the ball rolling, the '/bin/sh' gives refrence to sh, a command interpriter that most linux boxes have.

now you need to put your script together you can use normal command line options in this file ( as far as i know )
for example:

Code:

#!/bin/sh
#
# Description: Starts Vnc server at startup


echo "Starting VNCServer:"
/path/to/vnc/server && echo "Success"


the above is just basic script, its probably best if you look up using google 'linux shell scripts' and learning it properly. Plus look at some of your existing startup scripts and you will learn how to do one where you can type vncserver start or vncserver stop

dont forget to set the exeecute permission on the file you create or you may have problems

i would recomend starting vncserver last this gives the system the chance to load any program dependancys, like vnc needs network to be started first in order to function

i hope this helps

:)

note: if there is any one else out there at can do this in a better way i really would like to hear it please


Gianni 02-10-2003 06:27 AM

ok so with that simple script you gave me, I get and file or directory doesn't exits error.

I have used whereis to fin vncserver and get 2 locations
/usr/X11R6/binvncserver
and
/usr/X11/binvncserver

I have tried both with the same error message...

Quote:

Originally posted by Gianni
THANKS ! will try it out

Gianni 02-10-2003 06:58 AM

next error message
 
:)

ok I think I have most of it working, except I get this now:

couldn't find "xauth" on your PATH

trawling google as we speak but if you can help , would be great!

antken 02-10-2003 08:45 AM

right i think that because the PATH is not set untill you logon

if you logon and look in your home dir for a file called: .bash_profile

edit this file ( again using your favorite text editor ) some where in there there will be a line that says:

PATH=/bin:/sbin

or similar

copy this line out and paste it into your vnc start script ( above the execution command for vnc ( PATH needs to be defined before the vnc execute command ) )
then under the PATH= line type:

export PATH

that then activates the PATH varible for use in the rest of the script

hope this helps

Gianni 02-10-2003 08:52 AM

ok I ssh in and there is no file called .bash_profiel :)
sorry for being such a pain

I was reading about adding the path by using

PATH=$PATH:{path to be added}

can I do it that way ?

ps. I am loggin in as root.

Quote:

Originally posted by antken
right i think that because the PATH is not set untill you logon

if you logon and look in your home dir for a file called: .bash_profile

edit this file ( again using your favorite text editor ) some where in there there will be a line that says:

PATH=/bin:/sbin

or similar

copy this line out and paste it into your vnc start script ( above the execution command for vnc ( PATH needs to be defined before the vnc execute command ) )
then under the PATH= line type:

export PATH

that then activates the PATH varible for use in the rest of the script

hope this helps


antken 02-10-2003 09:04 AM

yes you could do that although, dont forget that this is at final boot and 9 times out of 10 on most distros do not define PATH until a user logs on


the best way to find out your path is to do the following:

logon as a user that can run VNC server successfully

when loged on type:

echo $PATH

it should return a line of stuff like /bin:/sbin:/usr/bin and so on

copy this line into your start up script for VNc server ( remember before the vnc server execute command )

then do 'export PATH' directly after it ( with out the quotes )

here is an example of the updated script to include the path statement:

Code:

#!/bin/sh
#
# Description: Starts Vnc server at startup

echo "Starting VNCServer:"

PATH={your paths here include one for the location of the vnc files }

export PATH

/path/to/vnc/server && echo "Success"


hope this helps!

:)

Gianni 02-10-2003 09:09 AM

will try that now, thanks!

the thing is I can vnc perfectly if I start it manually via ssh. Just thought I'd try and make it automatic :)

being very new to Linux it's quite an experience hehehe

thanks again



Quote:

Originally posted by antken
yes you could do that although, dont forget that this is at final boot and 9 times out of 10 on most distros do not define PATH until a user logs on


the best way to find out your path is to do the following:

logon as a user that can run VNC server successfully

when loged on type:

echo $PATH

it should return a line of stuff like /bin:/sbin:/usr/bin and so on

copy this line into your start up script for VNc server ( remember before the vnc server execute command )

then do 'export PATH' directly after it ( with out the quotes )

here is an example of the updated script to include the path statement:

Code:

#!/bin/sh
#
# Description: Starts Vnc server at startup

echo "Starting VNCServer:"

PATH={your paths here include one for the location of the vnc files }

export PATH

/path/to/vnc/server && echo "Success"


hope this helps!

:)


Gianni 02-10-2003 09:32 AM

ok :)

looks like I'm alsmost there...

I rebooted the machiine and on restart I get my "starting vnc now" message

then the system says that I will need a password for vnc and prompts for one.
After a few seconds the systems carries on with the boot as per normal. so almost there but still can't vnc straight in..will I have to include a password somewhere ?

antken 02-10-2003 09:57 AM

if you reboot again it should not ask for one

from memory, vnc should store the password in a file its just a case of the system creating a new one


hope this helped


All times are GMT -5. The time now is 04:34 PM.