VMware Cloud Community
FunkyD
Contributor
Contributor
Jump to solution

sftp in batch mode - please help me with my script

I have two servers - A and B, I want B to connect to A and pull all the .tgz files it sees in a directory.

I have the process working if I hard code the paths and servernames etc but cannot get to work using variables. Here are my two scripts:

#!/usr/bin/perl -w

my $esxbackupserver = '192.168.110.235';

my $sftpfile = '/vmfs/volumes/Data2/backup/sftpfile';

my $sftp = 'sftp';

system $sftp, '-b', '$sftpfile','$esxbackupserver';

The second file (sftpfile) is the command for sftp

cd /vmfs/volumes/Software/Backup

get *.tgz

When I run the script I get:

No such file or directory ($sftpfile).

As I say, hard coded it works fine but being a newbie to Perl I am obviously overlooking something - can anyone help? Thanks Smiley Happy

Message was edited by:

RDPetruska

Removed emoticon from subject line

0 Kudos
1 Solution

Accepted Solutions
dingding
Enthusiast
Enthusiast
Jump to solution

you should change single quote to double quote, since if you use single quote, the variable will not be resolved and the system will regard it as a hard coded string,

just change it from:

system $sftp, '-b', '$sftpfile','$esxbackupserver';

to

system $sftp, '-b', "$sftpfile","$esxbackupserver";

i am sure it will works.

---- Idleness is not doing nothing. Idleness is being free to do anything.

View solution in original post

0 Kudos
1 Reply
dingding
Enthusiast
Enthusiast
Jump to solution

you should change single quote to double quote, since if you use single quote, the variable will not be resolved and the system will regard it as a hard coded string,

just change it from:

system $sftp, '-b', '$sftpfile','$esxbackupserver';

to

system $sftp, '-b', "$sftpfile","$esxbackupserver";

i am sure it will works.

---- Idleness is not doing nothing. Idleness is being free to do anything.
0 Kudos