title: Regarding running multiple ssh commands using perl
body: <p>I am bit stuck here I want to ssh in to a machine and then run about 3 commands which are basically setup commands and then i want to return back to my machine with env variables of that machine</p>
  
  <p>like</p>
  
  <pre><code>setup1
  setup2
  setup3
  env &gt; envtext.txt.
  return back 
  </code></pre>
  
  <p>All this i have to do in perl</p>
  
  <p>i tried commands like
  <code>system("ssh @machine command1 &amp;&amp; command 2")</code> doesnt work</p>
  
  <p>is there something like?</p>
  
  <pre><code>system("ssh @machine command1 -cmd command 2 -cmd command 3")
  </code></pre>
  
  <p>if not than what is the best way to do it 
  like making a shell script then calling it or i can do it in perl itself without any shell scripts?</p>
  
  <p>code </p>
  
  <pre><code>#!/usr/bin/perl -w
  
  use Net::SSH::Perl;
  
  
  my $host = "address";
  my $user = "name";
  my $password = "password";
  </code></pre>
  
  <h1>-- set up a new connection</h1>
  
  <pre><code> my $ssh = Net::SSH::Perl-&gt;new($host,
      debug=&gt;0,
  
      identity_files =&gt; ['path to key'],
             options=&gt; ["StrictHostKeyChecking  no"]
             #interactive =&gt; yes,
      );
  </code></pre>
  
  <h1>-- authenticate</h1>
  
  <pre><code>$ssh-&gt;login($user,$password);
  </code></pre>
  
  <h1>-- execute the command</h1>
  
  <pre><code>my($stdout, $stderr, $exit) = $ssh-&gt;cmd("env");
  
  print $stdout;`
  </code></pre>
  
  <p>error it gives is Permission denied at ssh.pl line 25</p>
  
  <p>Thank you </p>