Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I wanted to make a script which ran automatically on login so I put it into the file ~/bash.profile, but it didnt run. When I put it in bashrc, it ran on opening a terminal.

What I was doing in the script was accessing a file in the pictures folder. I just added ./script.sh in ~/.bash_profile. How to make it run on login?

I'm using Unity on Ubuntu 11.10.

share|improve this question
    
Please post the script here for clarification. You should put things that should happpen on login time in the file ~/.bash_profile AFAIK. –  Herman Torjussen Feb 24 '12 at 18:58
    
Oh, and make sure it is executable; run chmod +x script.sh in case you haven't. –  Herman Torjussen Feb 24 '12 at 19:04
    
yes the script is executable –  user1065734 Feb 24 '12 at 19:11
    
i did tell that it ran in .bashrc –  user1065734 Feb 24 '12 at 19:12
2  
~/.bash_profile always runs when you log in in text mode (if your login shell is bash), but depending on the distribution and desktop environment, it may or may not run when you log into the GUI. How do you log in (e.g. gdm, kdm, text console, …), what desktop environment or session mananger do you use (e.g. Gnome, KDE, .xsession, …), and under what distribution (e.g. Ubuntu 11.10, Fedora Core 15, OpenBSD 5.0, …)? –  Gilles Feb 24 '12 at 19:14
show 3 more comments

2 Answers 2

up vote 1 down vote accepted

.profile and .bash_profile are files that are sourced by bash when running as a login shell such as when logging in from the Linux Text console or using SSH. They are not sourced when loading a new shell from an existing login such as when opening a new terminal window inside Unity or other graphical environment. .bashrc on the other hand is only sourced for non-login shells, though sometimes distros will source .bashrc manually from within the default .bash_profile. One workaround is to change Gnome Terminal to load the shell as a login shell from it's profile preferences, but then that would run every time you open up a new terminal window. Another option is to add it to the list of Startup Applications as suggested by @jrg.

share|improve this answer
    
ok then, can i add the script in startup application by terminal like is there any command to add a script to add in startup application –  user1065734 Mar 3 '12 at 13:37
add comment

I'm going to paraphrase from another answer, but I'll include all the basics.

You stated that you're using Unity, so search for and then open the program Startup Applications in the dash.

Then, click "Add".

enter image description here

Now, enter in the details of the script:

enter image description here

changing my example details with your own details

Click "Add" and you should be all set!

share|improve this answer
    
i did the same but the script doesnt work properly –  user1065734 Feb 25 '12 at 0:02
add comment

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.