Thread per SSH zwei Kommandos ausführen (22 answers)
Opened by bianca at 2020-08-02 13:30

bianca
 2020-08-02 13:30
#192447 #192447
User since
2009-09-13
6975 Artikel
BenutzerIn

user image
Hi!
Ich muss per SSH das aktuelle Verzeichnis wechseln und darin zip aufrufen. Wie geht das am einfachsten? Ich konnte weder mit CPAN:Net::SSH::Perl noch mit CPAN:Net::SSH2 eine Lösung finden. Entweder bleibt bis auf die vorletzte Zeile einfach alles still wie mit diesem Script:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
system('cls');

require Net::SSH2;
my $ssh2 = Net::SSH2->new();
$ssh2->connect('server .com') or $ssh2->die_with_error;
$ssh2->auth_password('user','pw') or $ssh2->die_with_error;
my $chan = $ssh2->channel() or $ssh2->die_with_error;
$chan->exec("cd /www/verz");
$chan->exec("ls");
print while <$chan>;
print "EXIT CODE: ",$chan->exit_status,"\n";
$chan->close;

oder die beiden Kommandos werden nicht in der selben Instanz ausgeführt wie hier
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
system('cls');

require Net::SSH::Perl;
my %params = (protocol => 2);
my $ssh = Net::SSH::Perl->new('server .com',%params);
$ssh->login('user','pw');

my ($out,$err,$exit);

($out,$err,$exit) = $ssh->cmd('cd /www/verz');
say '-' x 80;
say __LINE__;
say "\$out = '$out'";
say "\$err = '$err'";
say "\$exit = '$exit'";

($out,$err,$exit) = $ssh->cmd('dir');
say '-' x 80;
say __LINE__;
say "\$out = '$out'";
say "\$err = '$err'";
say "\$exit = '$exit'";

CPAN:Net::OpenSSH scheidet wohl aus: Net::OpenSSH verbindet nicht ohne Auskunft
Welche best practice Lösung gibt es da für Strawberry auf Windows?
Danke
10 print "Hallo"
20 goto 10

View full thread per SSH zwei Kommandos ausführen