#!/usr/bin/perl use strict; use warnings; use DateTime; #for some functionality that will come later. use Net::OpenSSH; my $cur_ip; my $cur_name; my $user = "deryoosername"; my $pass = "derpassverden"; my $sudo_pass = "dersoodoopass"; my $target_file = "target-ip-name.txt"; open (TARLIST, $target_file) or die "Can't open file: $!"; while () { chomp; ($cur_ip, $cur_name) = split /\t/; $cur_name =~ s/[\s]+//g; print "$cur_ip\t"; print "$cur_name\n"; my $ssh = Net::OpenSSH->new($cur_ip, user=>$user, password=>$pass, timeout=>2); next if $ssh_error and print "Can't SSH to host $cur_name\n" . $ssh->error . "\n"; my $remotepath = "/Pathto/remote/new.filename"; my $localpath = "/localdir/fileto.move $ssh->scp_put($localpath, $remotepath); my $file_list = $ssh->capture("ls -l"); print "$file_list\n"; my @sudo_out = $ssh->capture({stdin_data => "$sudo_pass\n"}, 'sudo', '-Sk', '-p', '', '--', 'su'); } close TARLIST;