Fedora Linux Support Community & Resources Center
  #1  
Old 6th July 2012, 07:18 PM
pratporetw Offline
Registered User
 
Join Date: Jun 2012
Location: India
Posts: 27
linuxfirefox
Error in Editing .bash_profile

I am working on Fedora 16. II have artha dictionary installed in my system. I was willing to start it automatically whenever i log in to my system. So i editted ~/.bash_profile file and just added the command artha at the end of the file. But when i rebooted the system, it asked me for the password but failed to load the GUI. Same thing happened when i added the command in /etc/profile.

Was i wrong somewhere??

Whats the correct way to add a command to run it at startup. And how to edit .bash_profile or /etc/profile file
Reply With Quote
  #2  
Old 6th July 2012, 07:30 PM
jpollard Offline
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,662
linuxfirefox
Re: Error in Editing .bash_profile

Wrong place to put it.

.bashrc is used when logging in in a terminal - but not when using the GUI. If you start a terminal window then it will be started... each time you open a terminal window, and I doubt that is what you want.

Modifying the /etc/profile will do the same changes everywhere - including the root login (where you likely don't want it).

There should be an "autostart" menu somewhere in Gnome (if you are using it), If using lxde/xfce then there is an autostart menu entry that allows you to specify what to start when you log in.

Now if you want it to start at boot time then you can't assume the GUI is available (nobody is logged in). So I really doubt that is what you want either.
Reply With Quote
  #3  
Old 7th July 2012, 12:32 AM
Gareth Jones Offline
Official Gnome 3 Sales Rep. (and Adminstrator)
 
Join Date: Jul 2011
Location: Leamington Spa, UK
Age: 31
Posts: 2,750
linuxfirefox
Re: Error in Editing .bash_profile

In GNOME, run "gnome-session-properties" in a terminal or Alt+F2, and add the program you want started there.
Reply With Quote
  #4  
Old 7th July 2012, 08:13 AM
pratporetw Offline
Registered User
 
Join Date: Jun 2012
Location: India
Posts: 27
linuxfirefox
Re: Error in Editing .bash_profile

Quote:
In GNOME, run "gnome-session-properties" in a terminal or Alt+F2, and add the program you want started there
this worked fine for me.

@jpollard
i have heard of that if you want to initialize something or some variables automatically when you login, then they must be kept in either /etc/profile (which is the first file to run while booting) or ~/.bash_profile (which is next to run for the user). That was the only reason why i put my command there. and i think /etc/profile gets run as root user and .bash_profile as current user. so why it failed to load my GUI.

---------- Post added at 12:43 PM ---------- Previous post was at 12:10 PM ----------

Suddenly i got one more query. What will happen if i put some echo command in ~/.bash_profile file. where will it display the output or where will it go because file will get run only once at the time of login, and at login, after entering username password it shows GUI not the terminal.

Please help m a bit confused
Reply With Quote
  #5  
Old 7th July 2012, 10:37 AM
Gareth Jones Offline
Official Gnome 3 Sales Rep. (and Adminstrator)
 
Join Date: Jul 2011
Location: Leamington Spa, UK
Age: 31
Posts: 2,750
linuxfirefox
Re: Error in Editing .bash_profile

Quote:
Originally Posted by pratporetw View Post
i have heard of that if you want to initialize something or some variables automatically when you login, then they must be kept in either /etc/profile (which is the first file to run while booting) or ~/.bash_profile (which is next to run for the user). That was the only reason why i put my command there. and i think /etc/profile gets run as root user and .bash_profile as current user. so why it failed to load my GUI.
No, it's (conceptually) simpler than that. (In practise the subtleties can be quite complex unfortunately.) Non are run on boot. When a user logs in, the commands in both /etc/profile and that user's ~/.bash_profile are executed as that user. /etc/profile also executes individual scripts in /etc/profile.d. However, this system is designed for text-terminal logins, and graphical logins complicate things. I think bash_profile is still loaded, but I may well be wrong. However the normal approach with graphical environments is to use the session manager to load programs.

Quote:
Suddenly i got one more query. What will happen if i put some echo command in ~/.bash_profile file. where will it display the output or where will it go because file will get run only once at the time of login, and at login, after entering username password it shows GUI not the terminal.
Most programs run in graphical mode without a terminal window have their output redirected to ~/.xsession-errors. I'm not sure how early in the login process that redirection is set up, although it should be as soon as possible, so I'd look there for output.
Reply With Quote
  #6  
Old 7th July 2012, 11:53 AM
jpollard Offline
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,662
linuxfirefox
Re: Error in Editing .bash_profile

In addition to the above...

Most things will work just fine putting echo commands in .bashrc...

Unfortunately, some things don't.

Some of the remote commands support an error stream, some don't. Those that don't tend to use the convention that when the first return (expecting a null byte) will error out when the character is not a null. This is caused by the bashrc echo commands being output before the remote application starts.

Most times, for single user systems, this isn't an issue. Exactly what happens with applications like sshfs (a remote file service capabililty supported by ssh) I'm not sure.
Reply With Quote
  #7  
Old 7th July 2012, 11:25 PM
pratporetw Offline
Registered User
 
Join Date: Jun 2012
Location: India
Posts: 27
linuxfirefox
Re: Error in Editing .bash_profile

I read the .xsession-errors and the only thing i understood is that it only saves the errors maybe of the boot time. I still didn't get the correct logic to know where the output will go if i put some echo commands in .bash_profile or /etc/profile.

.bashrc is executed everytime i start my terminal. So it has no problem in printing or executing what my echo command says.
My concern was with .bash_profile or /etc/profile.

Meanwhile i understood one thing on my own when i tried o execute "artha"(Command for Artha Dictionary) command at my terminal that the command needs some input from standard input when it gets executed. May be thats why it failed to load my GUI coz boot process got stuck in between expecting a user-input from terminal which is not available in graphical interface from the beginning.
Reply With Quote
  #8  
Old 8th July 2012, 06:37 AM
jpollard Offline
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,662
linuxfirefox
Re: Error in Editing .bash_profile

.xsession-errors doesn't have ANY boot time errors. Only errors after login.

For boot time errors you need to look in /var/log/Xorg.* files.

It sounds more like you need to understand how terminals work, and the commands that require input there is a shell thing called "redirection" that allows you to provide data from files, store data from the program, and record errors.

for that, I suggest a shell script to start the program, and have the script supply whatever the program needs.
Reply With Quote
  #9  
Old 8th July 2012, 08:13 AM
pratporetw Offline
Registered User
 
Join Date: Jun 2012
Location: India
Posts: 27
linuxchrome
Re: Error in Editing .bash_profile

Well i am quite familiar with redirection and shell scripts and i can do as you suggested buti dont know whats wrong with the "artha" dictionary. artha command is available in /usr/bin and can be executed but i found that it works only after you launch dictionary manually from GUI.

I wont create any more havoc here just for loading a dictionary.

but you are right that i need to learn basics and functionality of the terminal. I will be glad if you could suggest me a link or tutorial to learn more. i have got hands on shell programming and i am familiar with concepts. only thing i seek is guidance.

Last edited by pratporetw; 8th July 2012 at 08:45 AM.
Reply With Quote
  #10  
Old 8th July 2012, 08:35 AM
stevea Offline
Registered User
 
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,553
linuxfirefox
Re: Error in Editing .bash_profile

The explanations here leave me cold. "man bash" tells half the story ...


Quote:
INVOCATION
A login shell is one whose first character of argument zero is a -, or one started with the --login option.

An interactive shell is one started without non-option arguments and without the -c option whose standard input and error are
both connected to terminals (as determined by isatty(3)), or one started with the -i option. PS1 is set and $- includes i if
bash is interactive, allowing a shell script or a startup file to test this state.
So there are two distinct modifiers of shells based on how they are invoked. 'login' and 'interactive'

The man page continues (with redactions) ....
Quote:
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and
executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile,
~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.
....
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file
exists.

As a practical matter there is one login shell created very early in the login process when gdm or whatever greeter performs the authentication and before the Xsession begins. The controlling terminal at that time is also the session terminal - typically /dev/tty1 on Fedora. That login shell exits before your desktop appears.

During a Fedora gui login, the one and only login shell that is created for your login executes,
/etc/profile
~/.bash_profile
The global variables, PATH and such are inherited from this.


But a regular non-login interactive shell (like in your gnome-terminal) just executes,
~/.bashrc

-------

To make the plot thicker,
the default /etc/profile sources /etc/profile.d/*.sh generally
the default ~/.bash_profile sources ~/.bashrc
the default ~/.bashrc sources /etc/bashrc
the default /etc/bashrc also sources /etc/profile.d/*.sh unless it's a login shell

========

So the login bash shell executes
Code:
/etc/profile
     /etc/profile.d/*.sh
~/.bash_profile
    ~/.bashrc
        /etc/bashrc
while the normal fedora interactive non-login shell executes ...
Code:
~/.bashrc
    /etc/bashrc
        /etc/profile.d/*.sh
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
Reply With Quote
  #11  
Old 8th July 2012, 09:06 AM
pratporetw Offline
Registered User
 
Join Date: Jun 2012
Location: India
Posts: 27
linuxchrome
Re: Error in Editing .bash_profile

Thanks a lot stevea for the explanations here. i was familiar with execution hierarchy of the files but not with the types of shells and scripts they execute.

Although i didn't get my problem solved with artha but i got to new many interesting facts and also the source from where i should read. Manuals are probably best source one should refer first.

Thanks to all for valuable suggestions.
Reply With Quote
  #12  
Old 9th July 2012, 04:56 AM
robertdaleweir Offline
Registered User
 
Join Date: Oct 2005
Location: British Columbia, Canada
Posts: 418
linuxfirefox
Re: Error in Editing .bash_profile

Quote:
Originally Posted by stevea View Post
The explanations here leave me cold. "man bash" tells half the story ...




So there are two distinct modifiers of shells based on how they are invoked. 'login' and 'interactive'

The man page continues (with redactions) ....



As a practical matter there is one login shell created very early in the login process when gdm or whatever greeter performs the authentication and before the Xsession begins. The controlling terminal at that time is also the session terminal - typically /dev/tty1 on Fedora. That login shell exits before your desktop appears.

During a Fedora gui login, the one and only login shell that is created for your login executes,
/etc/profile
~/.bash_profile
The global variables, PATH and such are inherited from this.


But a regular non-login interactive shell (like in your gnome-terminal) just executes,
~/.bashrc

-------

To make the plot thicker,
the default /etc/profile sources /etc/profile.d/*.sh generally
the default ~/.bash_profile sources ~/.bashrc
the default ~/.bashrc sources /etc/bashrc
the default /etc/bashrc also sources /etc/profile.d/*.sh unless it's a login shell

========

So the login bash shell executes
Code:
/etc/profile
     /etc/profile.d/*.sh
~/.bash_profile
    ~/.bashrc
        /etc/bashrc
while the normal fedora interactive non-login shell executes ...
Code:
~/.bashrc
    /etc/bashrc
        /etc/profile.d/*.sh
Hi stevea
At what point does the /etc/gdm/Init/Default script run when booting and going to a GUI Login Screen? I put a chunk of code there under F16 and it worked for me. Now under F17 it does not work. Has something changed in the order or even the use of this script under F17?
Thanks
__________________
Robert :)
Kernel 3.9.10-100.fc17.x86_64 GNOME 3.4.2
CPU AMD 955 Quad Core
MoBo Gigabyte MA785GM-UD2H-AM3 MicroATX
Memory 8 Gigs OCZ DDR3-1333 PC-10666
Reply With Quote
  #13  
Old 9th July 2012, 10:20 AM
stevea Offline
Registered User
 
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,553
linuxfirefox
Re: Error in Editing .bash_profile

Main problem for OP ....
artha is an X11 program and there is no X11 display setup when ~/.bash_profile executes.
This belongs in the desktop(e.g. Gnome) 'session' control.

Quote:
Hi stevea
At what point does the /etc/gdm/Init/Default script run when booting and going to a GUI Login Screen? I put a chunk of code there under F16 and it worked for me. Now under F17 it does not work. Has something changed in the order or even the use of this script under F17?
Thanks
gdm is nominally the desktop manager, however it is responsible for the 'greeter' and login procedures. It runs as root (or else some special users). I wonder if you are having SELinux issues.

If you use 'pstree' you'll get a picture of how the current processes are inherited.
For me,
Quote:
├─kdm─┬─X
│ └─kdm───sh─┬─ssh-agent
│ ├─xfce4-session
│ └─xscreensaver
├─ksmtuned───sleep
Where kdm is the gdm analog.


Sadly the gnomes have been removing functionality from gdm for several years now. And the documentation of what it actually does in practice is not well documented (please someone - prove me wrong !). So 'look at the source' is the precise answer - sorry.
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
Reply With Quote
  #14  
Old 9th July 2012, 03:38 PM
robertdaleweir Offline
Registered User
 
Join Date: Oct 2005
Location: British Columbia, Canada
Posts: 418
linuxfirefox
Re: Error in Editing .bash_profile

Quote:
Originally Posted by stevea View Post
Main problem for OP ....
artha is an X11 program and there is no X11 display setup when ~/.bash_profile executes.
This belongs in the desktop(e.g. Gnome) 'session' control.



gdm is nominally the desktop manager, however it is responsible for the 'greeter' and login procedures. It runs as root (or else some special users). I wonder if you are having SELinux issues.

If you use 'pstree' you'll get a picture of how the current processes are inherited.
For me,


Where kdm is the gdm analog.


Sadly the gnomes have been removing functionality from gdm for several years now. And the documentation of what it actually does in practice is not well documented (please someone - prove me wrong !). So 'look at the source' is the precise answer - sorry.
Hi stevea
Thank you.
__________________
Robert :)
Kernel 3.9.10-100.fc17.x86_64 GNOME 3.4.2
CPU AMD 955 Quad Core
MoBo Gigabyte MA785GM-UD2H-AM3 MicroATX
Memory 8 Gigs OCZ DDR3-1333 PC-10666
Reply With Quote
  #15  
Old 10th July 2012, 08:58 AM
pratporetw Offline
Registered User
 
Join Date: Jun 2012
Location: India
Posts: 27
linuxfirefox
Re: Error in Editing .bash_profile

Hi stevea,

I was willing to mount my windows partitions automatically in login process so that i dont have to mount it explicitly afterwards. I put these lines of code in the ~/.bash_profile
Code:
mkdir /media/New\ VolumeC
mkdir /media/New\ VolumeD
mount /dev/sda2 /media/New\ VolumeC
mount /dev/sda3 /media/New\ VolumeD
But since mkdir dont have right to write /media and even sda2 and sda3 are accessible to only root (i feel) i got permission denied error and an alert in SELinuxTroubleshooter regarding "mkdir tried to write in /media".

Please help me to do my task
Reply With Quote
Reply

Tags
bash_profile, error, fedora, gui

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
F13 .bash_profile dysphorichermit Using Fedora 2 28th May 2010 09:12 PM
grubby "no suitable template" error causes no editing of grob.conf marko Fedora 12 Alpha, Beta & Release Candidates 3 12th July 2009 03:18 AM
.bash_profile laughingteacake Using Fedora 24 19th January 2008 09:17 PM
.bash_profile armen Using Fedora 3 12th March 2005 07:04 PM
.bash_Profile chitech Using Fedora 9 24th August 2004 08:50 PM


Current GMT-time: 04:32 (Monday, 21-04-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat