LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 08-20-2010, 08:09 AM   #1
mahmoodn
Member
 
Registered: May 2010
Posts: 426

Rep: Reputation: 16
Question running a script before login


I have a script and want to run it before user login. how can I place a script in startup process?
 
Old 08-20-2010, 08:22 AM   #2
ultimate_linux
Member
 
Registered: Mar 2010
Distribution: Ubuntu 10.04,opensolaris
Posts: 30
Blog Entries: 3

Rep: Reputation: 0
place that script in .bashrc or .bash_profile file located in home directory
 
Old 08-20-2010, 08:25 AM   #3
mahmoodn
Member
 
Registered: May 2010
Posts: 426

Original Poster
Rep: Reputation: 16
Are you sure it will work Before Login? It is important for me because I am doing my work remotely. If I restart my PC and it doesn't work, I will loose my IP!
 
Old 08-20-2010, 08:44 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399
Hi,

I'm not really sure what you want:

- Run a script every time a user logs in (be it that this script is run first in the login process).
or
- Run a script when you (re)boot your PC.

The first one is done every time someone logs in, the second one is only done once, no matter how many times a user logs in/out.

Please elaborate a bit so we can give an answer that will help you.
 
Old 08-20-2010, 08:47 AM   #5
mahmoodn
Member
 
Registered: May 2010
Posts: 426

Original Poster
Rep: Reputation: 16
Quote:
- Run a script when you (re)boot your PC.
This is what I want
 
Old 08-20-2010, 08:55 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399
Hi,

It depends a bit on the distro you are using, but most have a rc.local file for this purpose.

Look for /etc/rc.local or /etc/rc.d/rc.local.

This article might shed some light on this: Linux Init Process / PC Boot Procedure

EDIT: I just noticed you posted this in the ubuntu sub forum: Ubuntu - RcLocalHowto


Hope this helps.

Last edited by druuna; 08-20-2010 at 09:00 AM. Reason: Added Ubuntu link
 
Old 08-20-2010, 09:58 AM   #7
mahmoodn
Member
 
Registered: May 2010
Posts: 426

Original Poster
Rep: Reputation: 16
Ubuntu - RcLocalHowto was straight. I will try it. Thanks,
 
Old 08-20-2010, 10:02 AM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399
You're welcome
 
Old 08-22-2010, 03:17 AM   #9
mahmoodn
Member
 
Registered: May 2010
Posts: 426

Original Poster
Rep: Reputation: 16
I tried that but it didn't work. How can I debug?
 
Old 08-22-2010, 03:50 AM   #10
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399
Hi,

Without any information it will be hard to point you in the right direction. Here are some general pointers:

- What did not work,
- Does the script you want to add work as desired from the command line,
- Are there any error messages (during boot and/or in the log files),
- Did you retrace all the steps in the provided Ubuntu - RcLocalHowto link to exclude possible mistakes,
- Is /etc/init.d/local executed at boot? Remove all but the #!/bin/bash line and put the following line below it: echo "XXX Testing /etc/init.d/local XXX", this message should show up during booting. Probably one of the last lines.

If you encounter any specific problems/messages please post them so we can help you in more detail. If the error is script related: Please post the script too.

Hope this gets you going again.
 
Old 08-22-2010, 04:20 AM   #11
mahmoodn
Member
 
Registered: May 2010
Posts: 426

Original Poster
Rep: Reputation: 16
Quote:
- What did not work,
I have wrote a script to email my ip address (python sendip.py). I then added that command as described by RcLocalHowto.

Quote:
- Does the script you want to add work as desired from the command line,
yes. Whn I am logged in it does work

Quote:
- Are there any error messages (during boot and/or in the log files),
I greped log events with "python" but there is no result.

Quote:
- Did you retrace all the steps in the provided Ubuntu - RcLocalHowto link to exclude possible mistakes,
mahmood@localhost:~$ sudo update-rc.d local defaults 80
update-rc.d: warning: /etc/init.d/local missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
System start/stop links for /etc/init.d/local already exist.

Quote:
- Is /etc/init.d/local executed at boot? Remove all but the #!/bin/bash line and put the following line below it: echo "XXX Testing /etc/init.d/local XXX", this message should show up during booting. Probably one of the last lines.
I put "echo" command before and after "python sendip.py". I also put a print command inside the python file. Since I am using graphical interface of Kubuntu, I can not see any echo message in boot.

Also the python file first must put ip address in a file. But after login there is no such file and it shows the script didn't run.
 
Old 08-22-2010, 04:36 AM   #12
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399
Hi,

I'm not sure which log file(s) you checked (I greped log events with "python" but there is no result. doesn't say that much). You also need to check for errors and not specifically for python. Most log files can be found here: /var/log

Could you post the content of the /etc/init.d/local file and the full location (including the path) of the python script?
 
Old 08-22-2010, 04:41 AM   #13
mahmoodn
Member
 
Registered: May 2010
Posts: 426

Original Poster
Rep: Reputation: 16
I renamed local to S01local. Here is the content
Quote:
#!/bin/bash
echo "In local file"
/usr/bin/python /home/mahmood/sendip.py
echo "python script finished"
About logs, I have to say I see many many messages (system, kernel, authentication, ...) and don't know which one is suitable. One thing that I want to know is "how can I see the echo command in boot"?
 
Old 08-22-2010, 05:01 AM   #14
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399
Hi,
Quote:
Originally Posted by mahmoodn View Post
I renamed local to S01local.
Why?

The link provided clearly states it should be named /etc/init.d/local and _not_ /etc/init.d/S01local!!

I think this might be the problem.

Quote:
About logs, I have to say I see many many messages (system, kernel, authentication, ...) and don't know which one is suitable.
I'm not a kubuntu user, but most distro's have a /var/log/boot or /var/log/dmesg file (or something alike), which holds the boot messages.

If either of these exist: The /etc/init.d/local is executed at the end of the boot sequence, so the messages about it (if any) should be present neear the bottom of the log file.

Another file you could check is /var/log/messages. This file is not limited to the boot process (it is "activated" during the boot process and might hold some of the last actions done in the boot process).

Quote:
One thing that I want to know is "how can I see the echo command in boot"?
I do believe kubuntu uses the "quiet" option when booting. Check /boot/grub/menu.lst, you could consider removing the quiet part (Be careful!! If you don't know what you are doing, you might end up with an un-bootable system!! First concentrate on the other points I mentioned above and don't do this if you have any doubts!!).

Hope this helps.
 
Old 08-22-2010, 08:17 AM   #15
mahmoodn
Member
 
Registered: May 2010
Posts: 426

Original Poster
Rep: Reputation: 16
I redo my changes and wrote exactly what that guide says. From a friend I added "date > /home/mahmood/date-at-boot.txt" to the local file. After a reboot, date-at-boot.txt was created shows that the script was run in the start up process. However the python file didn't execute.

I will find the problem in the python mailing list and then write my experience here.

Thanks,
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a mount script on login targettl Linux - Software 4 10-12-2009 07:19 PM
Is it possibel to halt script running at login to root? n3mbers Linux - Newbie 11 07-22-2009 07:25 PM
Bash script not running on shell login. uncle-c Linux - Newbie 8 02-21-2009 09:41 AM
Running Script Upon Login edwin11 Linux - Software 7 06-26-2006 04:24 AM
Running a script at user login? brucebearau Debian 1 01-19-2004 04:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 03:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration