LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 10-08-2008, 01:41 PM   #16
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269

Quote:
Originally Posted by ceantuco View Post
hi guys!

I wrote my first useful shell script! now I would like to make it run as soon as I log in. where should I put the shell scrip to auto run?
thanks!
Also your title contradicts your question. Do you want to have this run when you login or before during boot?

If during login, use the .bash_login in you're users home directory. If at bootup before anyone logs in, put it in rc.local initialization file usually found in /etc/rc.d/
 
Old 10-08-2008, 02:33 PM   #17
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by trickykid View Post
The proper place would be .bash_login and not .bash_profile.
According to the man page, and my own experience, "~/.bash_profile" and "~/.bash_login" are essentially the thing with different names. You can double-check this by running
Code:
$ ls -l /etc/profile
and
Code:
$ ls -l /etc/login
and telling us which one exists on your system.
 
Old 10-08-2008, 02:37 PM   #18
ceantuco
Member
 
Registered: Mar 2008
Location: New York
Distribution: Debian
Posts: 809

Original Poster
Rep: Reputation: 88
hey guys! I added my script to ~/.bash_login but still it doesn't run. I want the script to run when I log in (sorry about the confusion with the title)

I have /etc/profile and I DO NOT have /etc/login

thanks guys!
 
Old 10-08-2008, 03:27 PM   #19
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally Posted by ceantuco View Post
hey guys! I added my script to ~/.bash_login but still it doesn't run. I want the script to run when I log in (sorry about the confusion with the title)

I have /etc/profile and I DO NOT have /etc/login

thanks guys!
What is this script and how do you know it's not being run?
 
Old 10-08-2008, 03:32 PM   #20
ceantuco
Member
 
Registered: Mar 2008
Location: New York
Distribution: Debian
Posts: 809

Original Poster
Rep: Reputation: 88
the script is supposed to ask what type of music I want to listen to then I will answer and depending my answer it would open my sound files. I know it is not running because it doesn't ask me anything. Is it possible that I'm doing something wrong?
 
Old 10-08-2008, 03:39 PM   #21
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally Posted by David1357 View Post
According to the man page, and my own experience, "~/.bash_profile" and "~/.bash_login" are essentially the thing with different names. You can double-check this by running
Code:
$ ls -l /etc/profile
and
Code:
$ ls -l /etc/login
and telling us which one exists on your system.
True but so is .profile, it's just more of a preference thing.

Here's why I separate them though from one another, .profile, .bash_login and .bash_profile are more for the initial things you want done upon login but on each terminal or shell you open. When I want something specific to run when I login as in a specific command, etc, I'll put it in .bash_login. This just keeps things tidy really to me.

Really you can have .bash_login, .profile and or .bash_profile to do everything you want initially when you login but .bashrc is really where it slightly differs from those and should be used for environment settings and aliases, etc. Say for instance if you're in X or GUI, each time you open a new terminal, it will search for .bashrc and not the others. I would imagine you might want a script to run upon initial login but not each time you want to run a new terminal or shell.
 
Old 10-08-2008, 03:41 PM   #22
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally Posted by ceantuco View Post
the script is supposed to ask what type of music I want to listen to then I will answer and depending my answer it would open my sound files. I know it is not running because it doesn't ask me anything. Is it possible that I'm doing something wrong?
Well, how are you logging in? I'd imagine logging in through a GUI instead of at the console it's not going to work like you anticipate.
 
Old 10-08-2008, 03:46 PM   #23
ceantuco
Member
 
Registered: Mar 2008
Location: New York
Distribution: Debian
Posts: 809

Original Poster
Rep: Reputation: 88
yes, I'm using the GUI! ok, so it is not going to work. what I wanted to do was something like a .bat file (for windows) where you could place it on the startup folder or the run key on the registry to make it run.
is that possible?
 
Old 10-08-2008, 03:48 PM   #24
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by ceantuco View Post
hey guys! I added my script to ~/.bash_login but still it doesn't run. I want the script to run when I log in (sorry about the confusion with the title)
Did you make "~/.bash_login" a directory and put your script in the directory? That is wrong! "~/.bash_login" and "~/.bash_profile" are files.

Also, did you do what I suggested and put some logging in "~/.bash_profile" (or "~/.bash_login)" to make sure everything is working the way you expect it to? If you are not adding any logging or debugging statements to your script, you are being lazy. Laziness will not solve your problems.
 
Old 10-08-2008, 03:55 PM   #25
ceantuco
Member
 
Registered: Mar 2008
Location: New York
Distribution: Debian
Posts: 809

Original Poster
Rep: Reputation: 88
wooowww you are being lazy. Laziness will not solve your problems are hard statements buddy. I'm not being lazy, at first I thought I had to create a dir and cp my shell to it but then I read that "~/.bash_login" and "~/.bash_profile" were files so I did that but it didn't work. Now I'm not a programmer so I DO NOT know how to add debugging statements.
 
Old 10-08-2008, 04:00 PM   #26
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by ceantuco View Post
yes, I'm using the GUI! ok, so it is not going to work. what I wanted to do was something like a .bat file (for windows) where you could place it on the startup folder or the run key on the registry to make it run.
When you login through the GUI, the contents of the "~/.bash_profile" (or "~/.bash_login") file will get executed, just as if you logged in via the console.

In your case, the root of the problem is that you have a "~/.profile" file, which takes precedence over the other two files. You need to call your script from the end of that file.
 
Old 10-08-2008, 04:02 PM   #27
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by ceantuco View Post
Now I'm not a programmer so I DO NOT know how to add debugging statements.
You should be able to add lines like
Code:
echo "This line got executed" >> ~/debug.log
to your "~/.profile" file and your script to see where things go wrong. If nothing shows up in "~/debug.log" then you know you have modified the wrong file or made some other mistake.
 
Old 10-08-2008, 04:06 PM   #28
ceantuco
Member
 
Registered: Mar 2008
Location: New York
Distribution: Debian
Posts: 809

Original Poster
Rep: Reputation: 88
Thanks David I'll give it a shot!
 
Old 10-08-2008, 04:06 PM   #29
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally Posted by ceantuco View Post
wooowww you are being lazy. Laziness will not solve your problems are hard statements buddy. I'm not being lazy, at first I thought I had to create a dir and cp my shell to it but then I read that "~/.bash_login" and "~/.bash_profile" were files so I did that but it didn't work. Now I'm not a programmer so I DO NOT know how to add debugging statements.
Probably in order for it to work is you need to kick off a terminal to then run the script within the shell prompt upon login into the GUI, since I'm guessing it's just a shell script and not a GUI program you created to start at login.

This may depend on what Desktop environment you use (might have to put it somewhere in an AutoStart ocnfiguration for Gnome, KDE or whatever you use) but something like this might work:

xterm -e "/path/to/script"

You can replace xterm with whatever terminal software you choose.

And we should really stop the nonsense about members being lazy. Don't assume, just help or move on without all the negativity.
 
Old 10-08-2008, 04:08 PM   #30
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally Posted by David1357 View Post
You should be able to add lines like
Code:
echo "This line got executed" >> ~/debug.log
to your "~/.profile" file and your script to see where things go wrong. If nothing shows up in "~/debug.log" then you know you have modified the wrong file or made some other mistake.
It still won't work unless this script is either a GUI program or it's launched within a terminal like I've pointed out. It probably is getting run but then dies cause it doesn't know where to run the output to when logging into the GUI.
 
  


Reply



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
automatic executing shell script at booting raj_deep2k1 Linux - Networking 3 01-25-2006 07:36 AM
How to run a shell script on boot up? AussieGit Linux - Newbie 4 11-02-2005 06:10 PM
Run shell script in RedHat after boot dmorse Linux - General 1 08-23-2005 01:54 PM
RH8 - how to automatically run a shell script at boot time nu-B Linux - Newbie 2 11-03-2003 02:47 PM
RH8 - how to automatically run iptables rules shell script at boot time nu-B Linux - General 1 10-29-2003 08:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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