I'm doing the scp like this:
my @args = ('/usr/bin/scp', '-p', $source, $destination);
my $scpresult = system(@args);
This works great and actually returns the correct return code so I can determine if the operation was successful or not.
Here is the problem: For reasons beyond my control, I have to run the perl script as root. However, the scp command needs to be run as a different user.
So, my perl script has to effectively change the system call from:
scp -p source destination
to
su - newuser -c scp -p source destination
I can't figure out how to get all the args right so the system function works. Adding the "su - newuser" piece breaks the system call from perl.
I've tried:
my @args = ('su', '-', 'newuser', '-c', 'scp', '-p', $source, $destination);
and I've tried
my @args = ('su - newuser -c scp -p $source $destination');
But both fail. Is there some way I can run my perl script as root and have that one system call be executed as a different user?