Reputation: 1
I try to write variable in end of file, but write it into STDOUT in local server some code:
$num = <STDIN>
my $cmd = "echo $dep_keys{$num} >> /root/1";
#$ssh->system({stdin_data =>$dep_keys{$num} },"echo >> /root/1");
#$ssh->error die "Couldn't establish SSH connection: ". $ssh->error;
#$ssh->system("echo $dep_keys{$num} >> /root/1");
$ssh->system($cmd);
I expect that the file will contain new line in the end of file.
Upvotes: 0
Views: 223
Reputation: 385809
use String::ShellQuote qw( shell_quote );
defined( my $num = <STDIN> )
or die("Invalid input");
chomp($num);
defined($dep_keys{$num})
or die("Invalid input");
my $cmd = shell_quote('printf', '%s\n', $dep_keys{$num}) . ' >>/root/1';
$ssh->system($cmd);
Fixes:
$num
(if any).echo
because echo
makes impossible to output some strings.Upvotes: 1