LinuxQuestions.org
Review your favorite Linux distribution.
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 03-02-2004, 12:59 PM   #1
draven
LQ Newbie
 
Registered: Mar 2004
Posts: 15

Rep: Reputation: 0
Question 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
 
Old 03-02-2004, 01:33 PM   #2
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
Add this to your users .bashrc , .bash_profile in their home directory or the global profile file in /etc called profile.
 
Old 03-02-2004, 01:36 PM   #3
markjuggles
Member
 
Registered: Nov 2003
Location: Chicago western suburbs
Distribution: Linux Mint
Posts: 75

Rep: Reputation: 15
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
 
Old 03-02-2004, 02:07 PM   #4
draven
LQ Newbie
 
Registered: Mar 2004
Posts: 15

Original Poster
Rep: Reputation: 0
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.
 
Old 03-02-2004, 02:25 PM   #5
markjuggles
Member
 
Registered: Nov 2003
Location: Chicago western suburbs
Distribution: Linux Mint
Posts: 75

Rep: Reputation: 15
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
 
Old 03-02-2004, 05:23 PM   #6
draven
LQ Newbie
 
Registered: Mar 2004
Posts: 15

Original Poster
Rep: Reputation: 0
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.
 
Old 03-03-2004, 01:54 PM   #7
markjuggles
Member
 
Registered: Nov 2003
Location: Chicago western suburbs
Distribution: Linux Mint
Posts: 75

Rep: Reputation: 15
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
 
Old 03-04-2004, 12:20 AM   #8
draven
LQ Newbie
 
Registered: Mar 2004
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks markjuggles I edited the script with the code you gave me and everything is working great now.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Howto start script at boot ? hendrixx Programming 3 11-15-2005 02:42 PM
Start programs from a shell script paraiso Linux - Newbie 4 04-29-2005 10:41 AM
howto start a perl script only from tuesday to friday at 8.00 am ? cccc Linux - Newbie 4 03-19-2005 05:23 AM
Howto Monitor elapsed time in a shell script rkrijger Linux - Software 2 03-11-2004 09:46 AM
howto start vpnclient with php script and sudo ? cccc Programming 1 01-12-2004 12:46 PM


All times are GMT -5. The time now is 02:51 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration