Reputation: 851
When I run this in the terminal, it works
/usr/bin/sftp -o "IdentityFile=/opt/apps/doc/bin/id_rsa" -b /opt/apps/doc/bin/batch.txt DMS2@convpc1
However, when I run this in perl script, nothing happen
system("/usr/bin/sftp -o \"IdentityFile=/opt/apps/doc/bin/id_rsa\" -b /opt/apps/doc/bin/batch.txt DMS2@convpc1");
I have been spending the entire day trying to figure out how to sftps my file and I cannot figure out the problem? Any suggestions?
Edit: I did some more testings. I put the entire command in a test.sh file. I ran the test.sh from terminal, it works. I changed the perl file so it is system("/opt/app/doc/bin/test.sh") and then ran it, nothing happen. I added printing statements before the system command, they work, but the system command still doesn't work since I don't see my file being moved.
Upvotes: 1
Views: 851
Reputation: 368
Try below
$result = "/usr/bin/sftp -o \"IdentityFile=/opt/apps/doc/bin/id_rsa\" -b /opt/apps/doc/bin/batch.txt DMS2\@convpc1";
system($result);
Are you getting any syntax errors? Try "perl -cw scriptname" and see the result.
I would suggest Net::SFTP which is very convenient for establishing SFTP connection.
Upvotes: 0
Reputation: 6592
The system command may be eating the quote character, and the '@' character needs escaping as \@.
Try this to see if you are really running the command you are trying to run:
my $cmd = "/usr/bin/sftp -o \"IdentityFile=/opt/apps/doc/bin/id_rsa\" -b /opt/apps/doc/bin/batch.txt DMS2@convpc1";
sys($cmd);
sub sys {
my ($cmd) = @_;
print "About to run '$cmd'\n";
(system($cmd) == 0) or die "Unable to run '$cmd' : $!";
}
Upvotes: 3