Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
04-29-2012, 05:33 AM
|
#1
|
LQ Newbie
Registered: Mar 2012
Location: Wirral, UK
Distribution: Ubuntu 22.04
Posts: 8
Rep: 
|
Running a script at startup
I'm trying to automatically run a script at startup (preferably once at boot time, but it would suffice to be able do it each time the user logs in). This is something I've done with ease many times in Windows and even in the past with older operating systems. Why is it proving so difficult with Linux? Using Ubuntu 11.10 - have tried two approaches but so far to no avail:-
1. Using cron, but when doing a crontab edit the system is just not saving the changes.
2. Adding a call to or inclusion of the script in ~/.profile. The latter exists by default in the Ubuntu installation whilst the files ~/.bash_profile and ~/.bash_login are absent. This should mean that .profile is executed at startup time, but there is no evidence that the required script is being run.
Can anyone please help?
Many thanks,
Andrew.
|
|
|
04-29-2012, 05:42 AM
|
#2
|
Member
Registered: May 2003
Location: İzmir
Distribution: Slackware64 15.0 Multilib
Posts: 779
Rep: 
|
1. crop will run scripts at fixed times. It does not try to run any script at startup at all.
2. .profile/.bash_profile scripts are sourced at time of log of the user so no it won't gets run at the startup.
What you should do is to add the script to /etc/rc.d. Check the dir for more information.
|
|
|
04-29-2012, 06:27 AM
|
#3
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Both Dillon and Vixie cron systems allow the use of @reboot in the crontab time field but adding to the boot scripts mechanism is a more natural way to achieve the same thing.
Interesting that ~/.profile does not seem to work. What is the evidence? How are you logging on?
Alternatively, you could hook into the graphical desktop session startup mechanism.
|
|
|
04-29-2012, 07:33 AM
|
#4
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,208
|
.profile is executed as a part of the login process and you will get no prompt during the execution. You can write logfile in your script and you will see if it was executed, also you can run it in the background.
|
|
|
04-30-2012, 03:44 AM
|
#5
|
LQ Newbie
Registered: Mar 2012
Location: Wirral, UK
Distribution: Ubuntu 22.04
Posts: 8
Original Poster
Rep: 
|
Many thanks for all the hints and tips - they helped me to look in the right direction for an answer. I got there in the end but not without more hurdles - I'll share my experience for the benefit of anyone else with a similar problem.
1. Basically all that was necessary to make something run at boot time was to add the appropriate lines of script on to the end of the /etc/init.d/rc.local script.
2. There was a problem with the script that I was trying to call anyway. I don't know whether a boot time script is validated before it is run - maybe it is in view of what happened. The script contained a read statement for terminal input (obviously not appropriate in a boot time script), although the read statement should not have actually been invoked with the paramaters that were being passed. Anyway, I managed to get the script to run by taking out the read statement and associated conditions.
3. Having modified the script however, I was getting a 'hiccup' during the initial login. As I started to type in my password, the system jumped to a black screen then back to the login screen with the password field cleared. On re-entering the password everthing was fine. Maybe this was to do with the fact that the script is performing quite a complex function - it actually calls a PHP script running in command line mode, which accesses a MySQL database and writes to a number of files.
4. The final solution was for the boot time script to write a dummy file just to say "I've booted". The .profile script then looks for that file and if it finds it, deletes it then calls a script to do the real job. The only thing I've discovered is that the system has to be set to do a manual login - an auto login at boot time seems to skip the operations in .profile.
5. It might look convoluted but it finally works and I'm happy.
|
|
|
04-30-2012, 04:43 AM
|
#6
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Thanks for sharing your findings
Threads can be marked SOLVED via the Thread Tools menu.
|
|
|
All times are GMT -5. The time now is 01:33 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|