aboutsummaryrefslogtreecommitdiffstats
path: root/ssh.pl
blob: a846637fd613fe9e0136c74a53de9dd3a2da80a4 (plain) (blame)
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
27
28
29
30
31
32
33
34
use strict;
use warnings;
use Net::OpenSSH;
use JSON;

my $host = "10.13.37.203";
# my $host = "192.168.122.184";
my $user = "lemon";

my $ssh = Net::OpenSSH->new($host, user => $user);
$ssh->error and die "Couldn't establish SSH connection: " . $ssh->error;

# $ssh->system("ls -al ~") or die "remote command failed: " . $ssh->error;

my $remote_host = $ssh->capture("hostname");

print "Working on $remote_host.\n";

# my @required_file = $ssh->capture("cat ~/.bashrc") or die "Cannot get requested file";
# for (@required_file) {
#     # print $_ if $_ =~ /^if*/;
#     # print $_;
#     # print $_ if !($_ =~ /^#/); # strips the comments
#     print $_ if ($_ =~ /^#/); # just the comments
# }
# print("\n");

# append to bollocks
# my $append_text = "Tits\n";
# $ssh->system({stdin_data => $append_text}, "cat >> bollocks.txt") or die "Cannot append text: " . $ssh->error;
my %test_hash = ('first_name' => 'Matthew', 'surname' => 'Lemon');
my $json_text = encode_json \%test_hash;
print "$json_text\n";