LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help with Howto start a shell script at boot (https://www.linuxquestions.org/questions/linux-newbie-8/help-with-howto-start-a-shell-script-at-boot-152647/)

draven 03-02-2004 11:59 AM

Help with Howto start a shell script at boot
 
I have a shell script to set a path to my java bin folder, the only problem is that I have to execute it every time using the "source" command once I log in. My questions are, is there a way to have either the shell script run once at every boot or is there a better way to set a path at boot. This is the shell script:

java_path="/usr/java/j2sdk1.4.2_03/bin";
PATH=$java_path:$PATH;

Thanks in advance,
Draven

trickykid 03-02-2004 12:33 PM

Add this to your users .bashrc , .bash_profile in their home directory or the global profile file in /etc called profile.

markjuggles 03-02-2004 12:36 PM

Do you need the path set at boot or when you login?

You probably just want to set your path automatically when you login.

To do this, edit your .profile. Files beginning with a dot are generally invisible. Use 'ls -a' to see it. If you don't have a .profile, just make one.
Finally, add your two lines above to your .profile.

Mark

draven 03-02-2004 01:07 PM

Quote:

Originally posted by markjuggles
Do you need the path set at boot or when you login?

You probably just want to set your path automatically when you login.

To do this, edit your .profile. Files beginning with a dot are generally invisible. Use 'ls -a' to see it. If you don't have a .profile, just make one.
Finally, add your two lines above to your .profile.

Mark


I would like to set it at boot so all users can use the commands in the path.

markjuggles 03-02-2004 01:25 PM

To change an environment variable for all users, change the setting in /etc/profile. You must be root to do so.

Be very careful when you change /etc/profile. Test your changes in another window *before* logging out. If you put a fatal error in this file, it will be difficult to fix!

Mark

draven 03-02-2004 04:23 PM

Quote:

Originally posted by markjuggles
To change an environment variable for all users, change the setting in /etc/profile. You must be root to do so.

Be very careful when you change /etc/profile. Test your changes in another window *before* logging out. If you put a fatal error in this file, it will be difficult to fix!

Mark

Alright since I'm a newb can you show me where to make the changes, since this is a critical file and I don't know exactly where to make, here is my current file:

[root@Hyponoia etc]# cat profile
# /etc/profile -*- Mode: shell-script -*-
# (c) MandrakeSoft, Chmouel Boudjnah <chmouel@mandrakesoft.com>

loginsh=1

# Users generally won't see annoyng core files
[ "$UID" = "0" ] && ulimit -S -c 1000000 > /dev/null 2>&1

if ! echo ${PATH} |grep -q /usr/X11R6/bin ; then
PATH="$PATH:/usr/X11R6/bin"
fi

if [ "$UID" -ge 500 ] && ! echo ${PATH} |grep -q /usr/games ; then
export PATH=$PATH:/usr/games
fi

umask 022

USER=`id -un`
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
HISTCONTROL=ignoredups
HOSTNAME=`/bin/hostname`
HISTSIZE=1000

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi

# some old programs still use it (eg: "man"), and it is also
# required for level1 compliance for LI18NUX2000
NLSPATH=/usr/share/locale/%l/%N

export PATH PS1 USER LOGNAME MAIL HOSTNAME INPUTRC NLSPATH
export HISTCONTROL HISTSIZE

for i in /etc/profile.d/*.sh ; do
if [ -x $i ]; then
. $i
fi
done

unset i
[root@Hyponoia etc]#

btw I do greatly appreciate the help you've given me thus far.

markjuggles 03-03-2004 12:54 PM

I would recomend duplicating the X11 path fragment:

# draven 03/03/04: Add Java SDK to the path
if ! echo ${PATH} |grep -q /usr/java/j2sdk1.4.2_03/bin ; then
PATH="$PATH:/usr/java/j2sdk1.4.2_03/bin"
fi


I put an identifier (name/date) above anything I change to help me find it later. Keeping a paper log book is wise. The logic is "if this isn't in the path, then add it".

Mark

draven 03-03-2004 11:20 PM

Thanks markjuggles I edited the script with the code you gave me and everything is working great now.


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