LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 06-22-2016, 05:16 AM   #1
shaleenmadlapure
LQ Newbie
 
Registered: Jun 2016
Posts: 11

Rep: Reputation: Disabled
source command doesn/t work when used inside shell script


Hi Everyone,

I am using an installer which is adding entry of environment variable in bash_profile file, when i am starting jetty server, it was unable to find that entry..when i run source ~/.bash_profile it rerlaods the bash profle and server starts succesfully without any issues..The problem is customer is not going to start a new session nor he is going to manually refresh the bash_profile.I tried to add the "source ~/.bash_profile" command inside a shell script and i called that shell script when i invoke the startup file of jetty server but it also doesn't work..Is there any other way we can reload the bash profile of current session?Any information you can provide me would be greatly appreciated.

Thanks,
Shaleen

Last edited by shaleenmadlapure; 06-22-2016 at 05:28 AM.
 
Old 06-22-2016, 05:40 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Fully specify the path rather than use the tilde (~).
 
Old 06-22-2016, 05:42 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
the problem is that you gave almost no information about the situation. All we know is: you have a bash_profile file and it was sourced. But how did you start your server, how did you invoke the startup file of jetty server, what kind of shell script is used to source ~/.bash_profile ?
Probably you missed you cannot change the environment of a running process by sourcing anything in a terminal. But it is only a wild guess.
 
Old 06-22-2016, 05:53 AM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by shaleenmadlapure View Post
Hi Everyone,

I am using an installer which is adding entry of environment variable in bash_profile file, when i am starting jetty server, it was unable to find that entry..when i run source ~/.bash_profile it rerlaods the bash profle and server starts succesfully without any issues..The problem is customer is not going to start a new session nor he is going to manually refresh the bash_profile.I tried to add the "source ~/.bash_profile" command inside a shell script and i called that shell script when i invoke the startup file of jetty server but it also doesn't work..Is there any other way we can reload the bash profile of current session?Any information you can provide me would be greatly appreciated.

Thanks,
Shaleen
Interesting.
Adding a source file to the jetty startup script? Yes, NO. Not gonna work.
 
Old 06-22-2016, 06:16 AM   #5
shaleenmadlapure
LQ Newbie
 
Registered: Jun 2016
Posts: 11

Original Poster
Rep: Reputation: Disabled
1)I have created startUp script startJetty.sh, whose contents are below
#!/bin/sh
sh refreshBashProfile.sh
java -Xms1024M -Xmx1024M -Djavax.xml.soap.MessageFactory=com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl -Dorg.eclipse.jetty.annotations.maxWait=1200 -Djetty.http.port=8080 -DaligneServerHost=10.253.80.38 -DaligneServerPort=1299 -Dtrmapp.properties=/home/donotlogoff/temp/jetty-distribution-9.3.5.v20151012/TRMClient.properties -Dwebserver.url=http://ap-pun-ws6801:8080/IdPRI-4.3.0 -jar start.jar


2)In the same directory I have created another shell file refreshBashProfile.sh which contains below command
#!/bin/sh
echo bash_profile refreshed succesfully
source ~/.bash_profile


3)Now when i run the startJetty.sh, echo statement is also printing properly but bash_profile is not refreshed.and server started with errors.if i manually refresh the bas_profile and starts server then server starts succesfully.
 
Old 06-22-2016, 06:20 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
sh refreshBashProfile.sh will fork a new shell and sourcing will be executed in the new shell. This new shell is actually finished just after the source command and dropped.
Sourcing in the child shell will not affect the parent in any way. That is not possible.
instead of sh refreshBashProfile.sh you need to execute the source command directly in that startJetty.sh.
 
Old 06-22-2016, 06:26 AM   #7
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Why not set env variables in startJetty.sh?
 
Old 06-22-2016, 06:32 AM   #8
shaleenmadlapure
LQ Newbie
 
Registered: Jun 2016
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by keefaz View Post
Why not set env variables in startJetty.sh?
Its an existing implementation ..can't change that
 
Old 06-22-2016, 06:36 AM   #9
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by shaleenmadlapure View Post
Its an existing implementation ..can't change that
You can invoke startJetty.sh with changed env, like
Code:
MY_ENV_VAR=1234 sh startJetty.sh
 
Old 06-22-2016, 06:45 AM   #10
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
jetty_base, jetty_home are all I ever set, I think last time I did it.
http://www.eclipse.org/jetty/documen...-and-home.html
from Jetty The Definitive Reference
 
Old 06-22-2016, 07:00 AM   #11
shaleenmadlapure
LQ Newbie
 
Registered: Jun 2016
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
sh refreshBashProfile.sh will fork a new shell and sourcing will be executed in the new shell. This new shell is actually finished just after the source command and dropped.
Sourcing in the child shell will not affect the parent in any way. That is not possible.
instead of sh refreshBashProfile.sh you need to execute the source command directly in that startJetty.sh.
You mean i will run like this.

#!/bin/sh
source ~/.bash_profile
java -Xms1024M -Xmx1024M -Djavax.xml.soap.MessageFactory=com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl -Dorg.eclipse.jetty.annotations.maxWait=1200 -Djetty.http.port=8080 -DaligneServerHost=10.253.80.38 -DaligneServerPort=1299 -Dtrmapp.properties=/home/donotlogoff/temp/jetty-distribution-9.3.5.v20151012/TRMClient.properties -Dwebserver.url=http://ap-pun-ws6801:8080/IdPRI-4.3.0 -jar start.jar
 
Old 06-22-2016, 07:04 AM   #12
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
yes, something like this. Just try it.
 
Old 06-22-2016, 07:08 AM   #13
shaleenmadlapure
LQ Newbie
 
Registered: Jun 2016
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
yes, something like this. Just try it.
I tried this its not working, what i did is just removed the path of java from bash_profile and then ran jetty.sh and still server started.
it means its not reloading the bash_profile.

when i opened the new session then its giving error java not found
 
Old 06-22-2016, 07:51 AM   #14
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
What user is used when modifying the ~bash_profile, and what user is used when starting the server?

Second, how is the startup script being invoked when it doesn't work?

Most services are not started by a user, but by the system.
 
1 members found this post helpful.
Old 06-22-2016, 08:02 AM   #15
shaleenmadlapure
LQ Newbie
 
Registered: Jun 2016
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
What user is used when modifying the ~bash_profile, and what user is used when starting the server?

Second, how is the startup script being invoked when it doesn't work?

Most services are not started by a user, but by the system.
1)Its the same user through which i have loggged in putty. its not an root user but customized user and same user is used in modification and starting server.

2)I am using command sh startJetty.sh to start the server.Even if you remove the java path and run the shell its taking the old path because environment property is not refreshed yet ..if you close the session then i am unable to run the startup script because now the bash_profile is reloaded.
 
  


Reply



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
[SOLVED] [SOLVED] bash script: can echo command, command works if I type, but command doesn't work in script ... why? hopeless_n00b Linux - Newbie 10 07-12-2018 05:57 AM
usage of history command inside shell script bsaheb Linux - Newbie 4 01-05-2010 08:55 PM
Problem executing mv command inside shell script pablogosse Linux - General 7 12-16-2009 12:21 PM
using source inside a shell script DEF. Programming 8 11-18-2009 05:52 PM
invoking windows command inside a shell script nano2 Programming 6 09-09-2009 03:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:54 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration