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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How we can pass the argument when calling shell script from perl script
# 1  
Old 03-19-2012
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: system ("sh","ftp") $tarball;

Code:
system ("sh","ftp");

Code:
#!/bin/bash
HOST='ftp.span.net'
USER='TPP'
PASSWD='TP'
SRCDIR='Splash'
tarball=$1
#FILE='$File.zip'
echo $FILE
/usr/bin/ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd $SRCDIR
put $tarball
quit
END_SCRIPT
exit 0

# 2  
Old 03-19-2012
Java

I don't see a reference to $FILE in the script but this should do it.

Code:
system ("ftpscript.sh file.zip");


Code:
#!/bin/bash
HOST='ftp.span.net'
USER='TPP'
PASSWD='TP'
SRCDIR='Splash'
tarball=$1
#FILE='$File.zip'
FILE=${1?file required}
echo $FILE
/usr/bin/ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd $SRCDIR
put $tarball
quit
END_SCRIPT
exit 0

# 3  
Old 03-20-2012
Net::FTP

If you're already executing a perl script, why not make the perl script use the FTP module and that way control the flow of execution through the FTP upload? Calling a bash script doesn't make it too easy to capture errors.

Code:
#!/usr/bin/perl

use strict;
use warnings;
use Net::FTP;

# you can set these before calling the script,
# $ SRCDIR=/var/tmp TARBALL=mytar.tar perl upload.pl
my $srcdir = $ENV{'SRCDIR'};
my $tarball = $ENV{'TARBALL'};

my $ftp = Net::FTP->new( "ftp.span.net", Debug => 0 );
$ftp->login( "user", "pass" ) || die( "couldn't login: ", $ftp->message );
$ftp->put( "${srcdir}/${tarball}" || die( "couldn't put: ", $ftp->message );
$ftp->quit;

# 4  
Old 03-20-2012
when my perl script run it alwas ask for password while uploading the tar file to FTP server and I don't want this.please let me know how could I avoild this in perl.
# 5  
Old 03-21-2012
Quote:
Originally Posted by anuragpgtgerman
when my perl script run it alwas ask for password while uploading the tar file to FTP server and I don't want this.please let me know how could I avoild this in perl.
If you're using the Net::FTP method (above) then you can provide the user/pass details within the perl script and it'll handle the login for you.
# 6  
Old 03-21-2012
Using the below method
Code:
{
     use Net::FTP;
     use Term::ReadKey;
     $remote_path="/NGGF";
     $err=0;
     print "\nUsername: hello\n";
     print "Password: ";
           ReadMode 'noecho';
              my $ftppass=ReadLine 0;
              chomp $ftppass;
              print "\n\n";
           ReadMode 'normal';
     $ftp = Net::FTP->new($ftphost, Debug => 1);    #make debug 1 if you face problem with ftp
     $ftp->login("hello", "$ftppass") or $err=1; #die "Could not log in!";
        push @ERRORS, "\n--------------------------------------------------------------------------------------------------------\n\n >>> Error($c): Password incorrect, please try again. $!\n\n" if $err;
      $ftp->quit if $err;
      errmsg() if $err;
     $ftp->cwd($remote_path);
     $ftp->binary();
        print "\n\nUpload in progress ...\n\n";
     $ftp->put($tarball);
     $ftp->quit;
  }

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass Oracle sql script as argument to UNIX shell script?

Hi all, $ echo $SHELL /bin/bash Requirement - How to pass oracle sql script as argument to unix shell script? $ ./output.sh users.sql Below are the shell scripts and the oracle sql file in the same folder. Shell Script $ cat output.sh #!/bin/bash .... (7 Replies)
Discussion started by: a1_win
7 Replies

2. UNIX for Dummies Questions & Answers

How to pass command line argument in shell script?

I need to write a shell script, when I run that script I should pass those arguments if not, then script should not run and pass the error message like invalid option - - should pass the argument. and Exit from the script (8 Replies)
Discussion started by: Nsharma3006
8 Replies

3. Shell Programming and Scripting

How to pass command line argument in shell script?

I need to write a shell script, when I run that script I should pass those arguments if not, then script should not run and pass the error message like invalid option - - should pass the argument. and Exit from the script https://www.unix.com/images/misc/progress.gif (1 Reply)
Discussion started by: Nsharma3006
1 Replies

4. 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

5. Shell Programming and Scripting

unable to pass value to user prompt from calling shell script

This is my script structure main script calls configure script which needs to be run as a different user and the configure script calls my application installation script. the application instruction script prompts the user for a directory which I need to pass from my main or configure script. ... (4 Replies)
Discussion started by: cmastays
4 Replies

6. 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

7. 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

8. 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

9. 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

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