Correct Syntax For Calling Shell Script in Perl Module


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Correct Syntax For Calling Shell Script in Perl Module
# 1  
Old 06-08-2005
Correct Syntax For Calling Shell Script in Perl Module

Problem: I have a shell script that will be called by a Perl module that will connect to a db and delete rows. The Perl module will be called by CRON. I am using a Perl module to call a shell script because I need to get the db connection from Perl.
Here is the Perl pseudocode:

#!/usr/local/bin/perl5.00506
use DBI;
##dblogin.pl provides a connection to the db. I retrieve the id, password, ##and host server variable from dblogin.pl
require "/cgi-bin/pswd/dblogin.pl";

$db_connection = $DB_id/$DB_pswd\@$DB_server;

#here is where I do not know what to do:
Call sh script RemoveRpts.sh and pass variable $db_connection
# 2  
Old 06-08-2005
Quote:
Call sh script RemoveRpts.sh and pass variable $db_connection
Maybe i didn't understand what you mean, but to me this looks simple: "$db_connection" is some sort of handle, id, ... - basically, it is something that fits into a variable.

Code:
RemoveRpts.sh $db_connection

will call a script RemoveRpts.sh and provide it with the content of this variable. Inside the script you can expand the first parameter by using "$1". Therefore the script could look like:

Code:
#!/bin/ksh

typeset db_connection=""

if [ -n "$1" ] ; then
     print - "Error: no database connection passed."
     exit 1
else
     db_connection="$1"
fi

# ... your code goes here

exit 0

Hope this helps.

bakunin
# 3  
Old 06-08-2005
If $db_connection is just a string containing the DB name/hostname/username/password etc. then it is easy.

system("/path/to/RemoveRpts.sh '$db_connection'");

If it is a filehandle opened by DBI or so, then you can't pass it as a command-line argument. A filehandle is not a string, and can't be passed on the cmdline.
# 4  
Old 06-08-2005
Thanks to all that have responded

I am going to use system to call my shell script. Thank you for your help.
# 5  
Old 06-08-2005
Quote:
Originally Posted by cbkihong
A filehandle is not a string, and can't be passed on the cmdline.
A filehandle is basically an integer and this can easily be passed to a script. If the script can make use of such an information is an entirely different matter of course - in fact it can't and I doubt that it is possible to write a program which can, because presumably the OS will not tolerate another process reusing filehandles created by another process. But then I'm out of software development for too long to be sure about that either.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

PERL: Calling a sub routine from another module - help!!!

Hi, I am an occasional PERL user. I am trying to call a sub routine (passing parameters) in perl module from a driver .pl file. I have been "tinkering" for a while now and have confused myself. Could someone please look at the code below and spot where I am going wrong. testPerl.pl ... (0 Replies)
Discussion started by: chris01010
0 Replies

2. Shell Programming and Scripting

Calling perl from shell script

I am calling a perl script from shell script. $ cat mah_appln_bkp_oln.ksh #!/bin/ksh . /udb/home/udbappln/.profile . /udb/home/udbappln/sqllib/db2profile Com=/udb/udbappln/utility/systemscripts/currentUMR perl $Com/backup.pl -d dbname --tsm --purgetsmcopies 21 --purgetsmlogs exit 0 ... (1 Reply)
Discussion started by: ilugopal
1 Replies

3. UNIX for Advanced & Expert Users

Calling PERL from a Korn shell script

I am currently in Afghanistan and do not have access to some of the resources I normally do back in the US. Just accessed this site and it looks promising! Hopefully you will not find my question too much of a waste of your time. I write mostly Korn Shell and PERL on Solaris systems for the... (2 Replies)
Discussion started by: mseanowen
2 Replies

4. Shell Programming and Scripting

Calling perl subroutine from shell script (sh)

Hi, ive a perl script, where it has a subroutine clear() in it, and i've one shell script which runs in background, from that shell script i wanted to call subroutine which is in perl script, that's perl script is not module, just simple script. Eg: perl script <test> #!... (4 Replies)
Discussion started by: asarunkumar
4 Replies

5. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

6. Shell Programming and Scripting

calling perl subroutine from perl expect module

All, Is it possible to call a subroutine from the perl expect module after logging to a system that is within the same program. My situation is I need to run a logic inside a machine that I'm logging in using the expect module, the logic is also available in the same expect program. Thanks,... (5 Replies)
Discussion started by: arun_maffy
5 Replies

7. Shell Programming and Scripting

Calling perl script in shell program

How to call a perl script in shell program / shell scripting. PLS HELP ME (2 Replies)
Discussion started by: hravisankar
2 Replies

8. Shell Programming and Scripting

How to call a shell script from a perl module which uses Filehandle to login

Hi Guru's, Pardon me for the breach of rules..... I have very little knowledge about Shell Programming and Scripting hope you guys help me out of this troble I have very little time hence could not find the right way to direct my queries. coming to the problem I need to call a... (2 Replies)
Discussion started by: saikrishna_tung
2 Replies

9. Shell Programming and Scripting

Plz correct my syntax of shell script

Dear all I am still bit new in shell script area.I am writing down a shell script which I guess somewhere wrong so please kindly correct it. I would be greatful for that. What I actually want from this shell script is that it will move all the files one by one to another server which can be... (2 Replies)
Discussion started by: girish.batra
2 Replies

10. Shell Programming and Scripting

calling a shell script from perl

Hi all, Not sure if this is the right forum to post query regarding perl script. I have a perl script which internally calls a shell script. My problem is that the shell script should be passed command line arguments. I call a shell script from perl using: system("sript.sh"); How do... (3 Replies)
Discussion started by: gurukottur
3 Replies
Login or Register to Ask a Question