Last active
November 16, 2021 09:50
-
-
Save gdjohn4s/573dd0180bd8d3de1467cc2c9f0a84d4 to your computer and use it in GitHub Desktop.
Simple remote command execution in perl using Net::SSH2 module.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
=begin | |
Author: john4s | |
Scope: Check file system disk usage on remote system | |
Version: v1.0 | |
DISCLAIMER: | |
To run this script you need to import your public rsa key on the server. | |
=cut | |
use warnings; | |
use strict; | |
use Net::SSH2; | |
# Configuration management | |
my $server = "YOUR IP"; | |
my $port = 22; | |
my $user = "USERNAME"; | |
# SSH Connection | |
my $ssh = Net::SSH2->new(); | |
$ssh->connect($server, $port) or die $!; | |
$ssh->auth_agent($user); | |
die "Failed to autenticate: $!\n" unless $ssh->auth_ok; | |
print("Connected to $server as $user\n"); | |
# Run remote commands | |
my $channel = $ssh->channel(); | |
$channel->exec("df -h"); | |
print("$_") while <$channel>; | |
$channel->close; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment