The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Parent/child Korn shell script help sasaliasim Shell Programming and Scripting 1 05-06-2008 02:09 PM
Include PERL script with in the unix shell script ganapati UNIX for Dummies Questions & Answers 1 04-29-2008 09:18 AM
Using Awk in shell script to extract an index of a substring from a parent string sandeepms17 Shell Programming and Scripting 2 11-07-2007 03:44 AM
How to call a perl script from a shell script anumkoshy Shell Programming and Scripting 2 08-30-2007 01:23 AM
returning to the parent shell after invoking a script within a script gurukottur Shell Programming and Scripting 5 09-26-2006 04:05 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-13-2007
Registered User
 

Join Date: Aug 2007
Posts: 10
Stumble this Post!
Exclamation How to Run a shell script from Perl script in Parent shell?

Hi Perl/UNIX experts,

I have a problem in running a shell script from my perl script (auto.pl).

I run the perl script using
perl auto.pl
from the shell prompt

The shell script picks the files in "input" folder and procesess it.

The shell script blue.sh has this code.

Code:
export JAVA_HOME=/opt/j2sdk1.4.2_02
export PATH=${JAVA_HOME}/bin:${PATH}
export MANPATH=${JAVA_HOME}/man:${MANPATH}
export RUNPATH=:.:/export/home/lib/activation.jar:/export/home/lib/commons-dbcp-1.1.jar:/export/home/lib/jdbc2_0-stdext.jar:/export/home/lib/libmqjbnd05.so:/export/home/lib/postcard.jar
export RUNPATH=$RUNPATH:/export/home/lib/ant.jar:/export/home/lib/commons-logging-api.jar:/export/home/lib/jms.jar:/export/home/lib/log4j-1.2.8.jar:/export/home/lib/providerutil.jar
export 
java -classpath $RUNPATH placeOrders ./input/
I tried to run this in perl script using
exec("blue.sh")
exec("./blue.sh")
`./blue.sh`
`sh blue.sh`


I get this error - ./blue: JAVA_HOME=/opt/j2sdk1.4.2_02: is not an identifier

But if i run it manually from the shell
Code:
./blue.sh
the script runs fine.

I guess the problem is because perl spawns a new shell.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-13-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Stumble this Post!
Have you tried putting

Code:
#!/bin/sh
at the start of the script?
Reply With Quote
  #3 (permalink)  
Old 08-13-2007
Registered User
 

Join Date: Aug 2007
Posts: 10
Stumble this Post!
Quote:
Originally Posted by porter View Post
Have you tried putting

Code:
#!/bin/sh
at the start of the script?

Yes. I did that. Still i get the same error.
Moreover, I can't run the shell script manually also.

$ ./blue.sh
./blue.sh: JAVA_HOME=/opt/j2sdk1.4.2_02: is not an identifier

$ sh blue.sh
blue.sh: JAVA_HOME=/opt/j2sdk1.4.2_02: is not an identifier
Reply With Quote
  #4 (permalink)  
Old 08-13-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Stumble this Post!
It does not like your exports.

Try

Code:
VARIABLE=value
export VARIABLE
Reply With Quote
  #5 (permalink)  
Old 08-13-2007
kahuna's Avatar
Registered User
 

Join Date: Apr 2007
Posts: 148
Stumble this Post!
Try ksh instead of sh
Code:
#!/bin/ksh
Reply With Quote
  #6 (permalink)  
Old 08-14-2007
Registered User
 

Join Date: Aug 2007
Posts: 10
Stumble this Post!
Quote:
Originally Posted by kahuna View Post
Try ksh instead of sh
Code:
#!/bin/ksh
Tried this...It does nto help. Still same error.

Any other option? Even if you are more than 50% sure please reply. It doesn't hurt trying.
Reply With Quote
  #7 (permalink)  
Old 08-14-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Stumble this Post!
Quote:
Originally Posted by hifake View Post
But if i run it manually from the shell
Code:
./blue.sh
the script runs fine.
What shell are you running normally?

What is it's complete path?

Try using that in the "#!....." first line.

Then switch to sh, by typing "sh", and then try and run the script.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0