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
Plz correct my syntax of shell script girish.batra Shell Programming and Scripting 2 06-06-2008 03:36 AM
calling a shell script from perl gurukottur Shell Programming and Scripting 3 10-05-2006 08:48 AM
Box A's perl script calling box B's shell script new2ss Shell Programming and Scripting 1 09-13-2006 03:17 AM
Calling CGI Perl in Shell script [urgent] DeepakXavier Shell Programming and Scripting 0 10-08-2005 10:51 PM
Calling privately installed module from script help please sdiva UNIX for Dummies Questions & Answers 2 02-09-2002 06:19 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 06-08-2005
Registered User
 

Join Date: Jun 2005
Location: Detroit
Posts: 24
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
Reply With Quote
Forum Sponsor
  #2  
Old 06-08-2005
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,235
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
Reply With Quote
  #3  
Old 06-08-2005
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,469
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.
Reply With Quote
  #4  
Old 06-08-2005
Registered User
 

Join Date: Jun 2005
Location: Detroit
Posts: 24
Thanks to all that have responded

I am going to use system to call my shell script. Thank you for your help.
Reply With Quote
  #5  
Old 06-08-2005
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,235
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:24 AM.


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

Content Relevant URLs by vBSEO 3.2.0