in reply to safely passing args through ssh
Given your update, where you have a piece of code on machine A, and you want to execute it on machine B, my solution is to put the code in a standalone file, copy it to the remote machine, and then execute it as normal over ssh. In my case, I have a shared filesystem (machines B through Z all mount a filesystem off machine A), so this is a trivial File::Copy. However, my code actually also handles test scenarios where the shared filesystem isn't yet mounted, and starts by doing an scp first. Because I'm not sharing ssh connections, this does necessitate a second ssh connection, but in my case, that's pretty trivial, and since I now actually use sshfs to mount that shared filesystem when it isn't already mounted via nfs, I don't even need that much.
Trying to copy arbitrary amounts of code across and execute the code all in a single go is going to be far from trivial. However, there's no reason that my previous solution wouldn't work if you formulate your code as a one-liner, e.g., if you set:
(don't put leading/trailing quotes on the script - the $script value should just be the code), this should be fine. However, this doesn't satisfy E(). You simply can't do it that way. You'll need to do:@cmd = ( '/usr/bin/perl', -e => quote_cmd($script) );
Basically, every time you add a new ssh layer, you'll have to re-quote_cmd it.@cmd = ('perl', '-e', $script); # pick which one you need: system(@cmd); system('ssh', $host, quote_cmd(@cmd)); system('ssh', $proxy, quote_cmd('ssh', $host, quote_cmd(@cmd))); # etc., etc.,
|
|---|