The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-08-2005
mh53j_fe mh53j_fe is offline
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
  #2 (permalink)  
Old 06-08-2005
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
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 (permalink)  
Old 06-08-2005
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
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 (permalink)  
Old 06-08-2005
mh53j_fe mh53j_fe is offline
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.
  #5 (permalink)  
Old 06-08-2005
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0