Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Well, I do know that for a single script the question is to just put the corresponding file in directory /etc/rc.local, right? But, what if this script depends on other files (i.e. a few scripts and a couple of text files)? What should I do in order to avoid making this certain folder a mess?

share|improve this question
    
/etc/rc.local is not a directory but a simple file. –  sputnick Oct 25 '12 at 0:05
    
Alright. But either way the question stills. What do I have to do? –  user88349 Oct 25 '12 at 0:08

2 Answers 2

If by depends, you mean it uses and/or calls them, that should not matter. You can just add a line to the end of the rc.local file as a command to call the main script and it should just work.

There is an alternative to rc.local, atleast on desktop versions. You can use the Startup Applications app to add your script to it. The difference between the two methods, other than CLI vs GUI version of adding is that rc.local scripts are run as ROOT and the startup applications as your user.


Edit

From the comments, your problem becomes clearer. It seems that the script is using relative paths to access the dependency, which I'm guessing isn't code. The working directory of the above two methods are either /root/ or /home/<user name/, thus the dependencies dont load.

Easiest fix is to cd to the folder before invoking the python script. Either of these should work: - Use cd /home/..../.../ && python perdc_task.py as the command in either of those two methods. - If that doesnt work, make a script(.sh should do) which calls the above command and call this script in the above 2 methods.

The more elegant way of doing it is - Do the cd from inside the python script by programatically determining its path - Or Use the above path to access the dependencies by absolute path


Edit2

Ubuntu might have moved away from rc.local in favor of upstart. Try to see if using upstart as in this question works for you.

share|improve this answer
    
I would prefer the GUI version. Unfortunately it doesn't work for me. I used this command: python /home/.../.../.../perdc_task.py Any ideas? –  user88349 Oct 29 '12 at 14:03
    
either of these methods should work, and yet they dont.. sounds like there might be something you are missing.. what do you mean it doesnt work? Try to write out a log to see if it is starting.. is it possible it is running but terminating or something? –  Karthik T Oct 29 '12 at 15:31
    
try python /home/.../.../.../perdc_task.py > /home/<your username>/Documents/perdc_task.log and check out if anything is written into the log file –  Karthik T Oct 29 '12 at 16:11
    
Thanks for your answer. However, a strange thing is happening. The above script doesn’t run unless I do CD so that the current directory is where the script is located. If I do that, everything works fine and noting is written on the log file. If I don't do that, an error message is shown in terminal, however nothing is written on the log file. Any ideas? –  user88349 Oct 29 '12 at 23:19
    
I tried it but still have problems. Now the scripts are executed directly through the console (I mean, without the need of doing cd beforehand), however I face problems when I use the startup application feature of Ubuntu. Any help on that? –  user88349 Oct 30 '12 at 16:29

If you have cron enabled (which you should) there is a special @reboot command which runs on startup. I am unsure of this works on cold boots though, but from what I can see it does.

If it works, you just write a script, plonk it in some clean and organised directory, then call it through cron.

See: Here and Here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.