LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Best method for automatic command execution every time a system boots up (https://www.linuxquestions.org/questions/linux-newbie-8/best-method-for-automatic-command-execution-every-time-a-system-boots-up-4175472542/)

Ahsaniqbalkmc 08-07-2013 04:55 PM

Best method for automatic command execution every time a system boots up
 
I have a raspberry pi which I use without a monitor. I boot it up, connect to it via SSH, and then start a VNCserver on it. I have to do it every time I start the device or reboot it.

I would like to automate the process. Like in windows, I would add the vncserver to startup programs and it would automatically start every time the system boots up.

I need to know how can I do this on raspbian wheezy. I tried to find a solution by googling but I wasn't able to successfully achieve what I wanted. Some websites talked about /etc/rc.local, some about crontab etc etc.

As I am new to linux so I don't understand them. So I would love to know what is the best method to do it and then I would like to go deeper and understand the procedure.

Thankx

Kustom42 08-07-2013 04:57 PM

Add it to /etc/rc.local. Commands in this file will be executed after all other init scripts have completed.

Ahsaniqbalkmc 08-07-2013 07:33 PM

Thanks @Kustom42

I added the following line to the /etc/rc.local file before the "exit 0" and it worked like a charm

sudo vncserver :1 -geometry 1340x74 -depth -16

Taking advantage of this discussion, I would like to ask you "What is rc.local file?". I don't have much experience with Linux machines so I have to ask this noob question.

Kustom42 08-08-2013 06:43 PM

The previous post basically explains it.

rc are run level scripts, you have a bunch of them that each service creates so it starts on boot. the rc.local is for custom commands and such you want executed after all the other rc scripts are.


do some ls'ing on /etc/rc5.d/


http://www.tldp.org/LDP/sag/html/run-levels-intro.html

chrism01 08-08-2013 06:59 PM

Some articles
https://en.wikipedia.org/wiki/Linux_startup_process
http://luv.asn.au/overheads/linux-startup.html

szboardstretcher 08-13-2013 03:17 PM

I have always lamented that rc.local was not named rc.last

(RC = Run Control, IYI)

Ahsaniqbalkmc 08-14-2013 05:58 AM

Thanks @Kustom42, @chrism01 for the helpful links... I didn't grasp all of what was in those articles but at least now I know more than before reading those...

lleb 08-14-2013 06:52 AM

Quote:

Originally Posted by Ahsaniqbalkmc (Post 5009062)
Thanks @Kustom42, @chrism01 for the helpful links... I didn't grasp all of what was in those articles but at least now I know more than before reading those...

and thats the key. now that you have some knowledge you can experiment, fail, experiment some more, and succeed, or at the very least ask more detailed questions.

chrism01 08-14-2013 07:47 PM

lleb++ ... couldn't have put it better myself ;)


All times are GMT -5. The time now is 05:27 PM.