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;
system ("sh","ftp");
#!/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
I don't see a reference to $FILE in the script but this should do it.
system ("ftpscript.sh file.zip");
#!/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
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.
#!/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;
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.
Using the below method
{
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;
}