Calling a Perl script in a Bash script -Odd Situation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling a Perl script in a Bash script -Odd Situation
# 1  
Old 09-15-2011
Calling a Perl script in a Bash script -Odd Situation

I am creating a startup script for an application. This application's startup script is in bash. It will also need to call a perl script (which I will not be able to modify) for the application environment prior to calling the application. The problem is that this perl script creates a new shell when started and will not automatically exit. Therefore it will sit until I enter “exit”, then the application will start, but I lost the environment I need.

Simple Application Script Example:
Code:
#!/bin/bash
 
# call perl script that sets the application environment
Perl_env_script
 
# startup application
APP_START

Putting the “Perl_env_script” in the background still placed the needed environment outside the application and I don't get the environment I need when the application starts.

I also want to mention that I can manually type the command `Perl_env_script`, which leaves me in its current shell, where I can manually start the application normally. Unfortunately, this will be used from an application menu launcher and so I need to automate this process.

If this cannot be done, then I'll take the time to go through the perl script (which is huge and confusing) to gain the environment I need, but I was hoping there was an easier way.

Thanks for your help!
Frustrated Newbie

---------- Post updated at 03:23 PM ---------- Previous update was at 12:13 PM ----------

I got it working, but it's a two-step process:

I created a one-line script that calls the Perl script within an xterm:
Code:
xterm -e Perl_env_script

Once the xterm is up, the user will have to start another script to start the application:

Code:
APP_START:
#!/bin/sh
export APP_HOME=/testapps/apps
 
${APP_HOME}/bin/APPclient

I don't like the two-step process, but it is working. I might receive some complaints from users. So, if you know of a more streamlined way of doing this, please let me know.

Again, Thanks!
# 2  
Old 09-15-2011
Hi,

Thank you for posting your own solution. I had been reading it but no idea. I hope it works without complaints Smilie

Regards,
Birei
# 3  
Old 09-15-2011
No matter how you run it, your perl script gets its own process, with its own independent set of environment variables. Children get copies of their parents' environment, nothing more. The perl script has to run your application, so it gets copies of perl's environment vars.

An environment script that can't take any arguments makes no sense. Maybe you can echo appname | perlscript? Or perlscript appname?

Post the contents of the environment script please.

Last edited by Corona688; 09-15-2011 at 05:40 PM..
# 4  
Old 09-15-2011
How about running the perl script in the current shell by doing...
Code:
. /path/to/Perl_env_script

# 5  
Old 09-15-2011
Quote:
Originally Posted by shamrock
How about running the perl script in the current shell by doing...
You can't run perl code in a shell...
This User Gave Thanks to Corona688 For This Post:
# 6  
Old 09-15-2011
Thanks guys, appreciate the feedback. I'll definitely look into Corona688's suggestions.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Calling bash script from CGI

Hi, I am having two individual scripts Script 1): CGI script - is a simple script which trigger bash script Script 2): Bash script - is a script which execute which collects file system utilization information from all the Unix servers If I am executing CGI script manually from command... (2 Replies)
Discussion started by: Naveen.6025
2 Replies

2. Shell Programming and Scripting

Calling a perl script from another script

hi, i have 2 perl scrips, a.pl and b.pl. i want to call b.pl from a.pl and once b.pl is executed, would like to return value from b.pl to a.pl. ######## a.pl ############## $test = `./b.pl 1`; print "file a: $test \n"; ####### b.pl ############## print "file b: $ARGV \n"; return 100; ... (3 Replies)
Discussion started by: hemalathak10
3 Replies

3. Shell Programming and Scripting

calling a shell script present on another server using perl script.

Hi, I am working on a sever A. I want to write a perl script to execute a shell script persent on the server B. please help me in this. thanks in advance. (3 Replies)
Discussion started by: anandgodse
3 Replies

4. Shell Programming and Scripting

Calling function from another bash script

I would like to call functions from another bash script. How can I do it? Some code More code (11 Replies)
Discussion started by: kristinu
11 Replies

5. Shell Programming and Scripting

How we can pass the argument when calling shell script from perl script

Can someone let me know how could I achieve this In one of per script I am calling the shell script but I need to so one thing that is one shell script call I need to pass pne argument.In below code I am calling my ftp script but here I want to pass one argument so how could I do this (e.g:... (5 Replies)
Discussion started by: anuragpgtgerman
5 Replies

6. Shell Programming and Scripting

calling a perl script with arguments from a parent perl script

I am trying to run a perl script which needs input arguments from a parent perl script, but doesn't seem to work. Appreciate your help in this regard. From parent.pl $input1=123; $input2=abc; I tried calling it with system("/usr/bin/perl child.pl $input1 $input2"); and `perl... (1 Reply)
Discussion started by: grajp002
1 Replies

7. Red Hat

Calling BASH script from JAVA

Hi, I am trying to call a bash script from a java file. Code to call bash script will look like: Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec("mybashfile.sh"); It is succesfully calling the bash file. I am using simple rm commands in the script to remove... (0 Replies)
Discussion started by: lakshman.forums
0 Replies

8. Shell Programming and Scripting

Calling bash command in perl script

Hi, I have tried several times but failed, I need to call this script from the perl script. This one line script will be sent to /var/tmp/error Bash command: /usr/openv/netbackup/bin/admincmd/bperror -backstat -l -hoursago 12 |awk '{ print $19, $12, $14, $16}'|grep -vi default|sort >... (12 Replies)
Discussion started by: sQew
12 Replies

9. Shell Programming and Scripting

Calling 3 perl script from one

hi all, I have 3 perl scripts a.pl,b.pl and c.pl each of these work when i pass a date for eg: perl c.pl 2010-05-27 now i want to write a perl script that would call the 3 scripts and make it run all the 3 scripts (a.pl,b.pl,c.pl) parallelly rather than 1 after the other....... pls... (2 Replies)
Discussion started by: siva_nagarajan
2 Replies

10. Shell Programming and Scripting

Calling a shell script from a perl script

Hi, I have one shel script which returns some value and I am calling this shell script from a perl script which needs the out put/return value of shell script. But I don't know how to collect the output/return value of the shell script. Can any one give some idea on it? For example: The... (1 Reply)
Discussion started by: siba.s.nayak
1 Replies
Login or Register to Ask a Question