Go Back   openSUSE Forums > Archives > SF Archives > ARCHIVES - Miscellaneous
Forums FAQ Members List Search Today's Posts Mark Forums Read

ARCHIVES - Miscellaneous Questions about SUSE Linux that don't fit anywhere else

 
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-Aug-2004, 18:36
nicolet
Guest
 
Posts: n/a
Default

I am struggling a bit with the best way to add a path for use globally on my SuSE 9.1 system. I assumed that there would be a YAST setting but I have not been able to find one. Google pointed me in the direction of /etc/profile which I opened but that file strongly suggests that I use the profile.local for adding PATH variables. I looked for this file and it did not exist so back to Google. I have since created the /etc/profile.local file and included the following commands.
#profile.local
#local system settings
#add nessus to PATH variable
PATH="$PATH":/usr/local/nessus/bin:/usr/local/nessus/sbin
export PATH

This appears to work but I end up getting TWO entries for the above directories once I restart my session.

Can someone enlighten me please?
  #2 (permalink)  
Old 13-Aug-2004, 14:11
nicolet
Guest
 
Posts: n/a
Unhappy

Patiently waiting to be inlightened.................... ;-)
The more I mess around with installs the more I keep running into this. I'm looking for a 'best practice' suggestion. It seems so simple so maybe I am just dense but any help would be appreciated.

  #3 (permalink)  
Old 13-Aug-2004, 21:34
Cynric
Guest
 
Posts: n/a
Default

I'm not so hot at paths yet, but since no one has pointed out any suggestions ... I run bush by default (I think it may be the default for SuSE) and add the exports and paths to the /home/<user>/.bashrc. Hope that helps or at least points you in a different direction.
  #4 (permalink)  
Old 14-Aug-2004, 20:35
rake
Guest
 
Posts: n/a
Default


What you have looks fine.

But I have noticed the same problem with multiple entries in $PATH. It seems that at after a reboot and logging in, that /etc/profile and $HOME/.profile are both getting run twice. Anyone else seeing this problem or know what might be causing it?

I fixed the double entry problem by borrowing a function from my old Red Hat install called "pathmunge". I put the following in a file (/local/etc/pathmunge).

###################
pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^|$1($|" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}

shopath () {
echo -e ${PATH//:/"\n"}
}

export pathmunge shopath
######################

Then, within your /etc/profile.local, you could do:

. /local/etc/pathmunge
pathmunge /usr/local/nessus/bin after
pathmunge /usr/local/nessus/sbin after

which will add /usr/local/nessus/bin to your $PATH, unless it is already there.
The "after" puts it at the end. Leave off the "after" to put the new path at the beginning of $PATH.

The "shopath" function is just a convenience to print out $PATH one element per line. Just run the command "shopath" from a shell. (after running the command ". /local/etc/pathmunge" to load the file with the function defs.

  #5 (permalink)  
Old 15-Aug-2004, 00:16
arun
Guest
 
Posts: n/a
Default

Quote:
Originally posted by nicolet@Aug 13 2004, 20:11
The more I mess around with installs the more I keep running into this.* I'm looking for a 'best practice' suggestion.
First, I am unsure why you are so worried about this problem. Is there anything beyond aesthetic reasons? There simply is no harm I can think of because you have some directories repeated twice in your $PATH variable. If there is something, I would like to be enlightened as well

Ok, now to really answer your question (this method may not work on other distributions) -- the reason this happens is because your '/etc/profile' is run twice. I am not sure when these things happen exactly, but I can say for certain from what you see that it is run twice. What can you do? Well, suse exports an environment variable called 'PROFILEREAD' which is set to 'true' when the profile is read once. So, you can test for its value and only set your PATH if this variable is not set already. Something like
Code:
if test -z "$PROFILEREAD"; then
PATH="$PATH":/usr/local/nessus/bin:/usr/local/nessus/sbin
export PATH
fi
A better practice, I would say, is to create your own variable (say, LOCALPROFILEREAD or something) and set it to true at the end of your /etc/profile.local. That way, you can test for this variable, and not depend on suse exporting a variable named 'PROFILEREAD' in future releases. Of course, such a method will work in other distributions too.
 

Bookmarks

Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2