Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Pass local bash script to remote host via SSH (updated)

by soonix (Canon)
on Jun 24, 2020 at 06:20 UTC ( #11118404=note: print w/replies, xml ) Need Help??

in reply to Pass local bash script to remote host via SSH

use strict; use warnings; open(my $out_fh, "|-", qw'ssh <remotehost> bash -s') or die "Can't sta +rt ssh: $!"; print$out_fh <<EOF; <local bash script written here> EOF close $out_fh or die "Error flushing/closing pipe to ssh: $!";
see open, and Quote and Quote like Operators (watch the semicolon after <<EOF - the <<EOF syntactically stands in for the complete string)

Update:should you need variables interpolated in your 'ssh <remotehost> ...', you need to create the list in a different way, because qw doesn't interpolate variables.

Replies are listed 'Best First'.
Re^2: Pass local bash script to remote host via SSH
by haukex (Bishop) on Jun 24, 2020 at 09:43 UTC
      Good catch, updated

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11118404]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2021-10-22 04:44 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (85 votes). Check out past polls.