use Net::OpenSSH; my $host = '192.168.109.10'; my $user = 'admin'; my $password = 'admin'; my $port = '22'; my $ssh = Net::OpenSSH->new( host =>$host, user => $user, port => $port, password => $password); $ssh->error and die "Couldn't establish SSH connection: ". $ssh->error; my $fichier_dst = "$host\.txt"; open (FH_OUT, '>', '/home/alexandre/Python_script/CISCO/' . $fichier_dst);; my $cmd1 = 'conf t'; my $cmd2 = 'hostname TOTO'; my $cmd3 = 'exit'; $ssh->system("$cmd1"); $ssh->system("$cmd2"); $ssh->system("$cmd3"); my $cmd4 = 'sh run \| i hostname'; my ($out, $err) = $ssh->capture2("$cmd4"); $ssh->error and die "remote find command failed: " . $ssh->error; print "$out\n"; print FH_OUT $out; close(FH_OUT);