Perl programming
Student name
Institution
Date: 7/6/2017
Identify modules from adapters.
"Win32::GUI is a Win32-arrange native graphical UI tool kit forperl. Basically, it's a XS use of
most of the limits found in user32.dll and gdi32.dll, with a challenge oriented perl interface and
an event based trade appear". (Win32::GUI,n.d). Net::SSH::Perl This module gives aperl
interface to the SSH1 and SSH2 Secure shell traditions. The module has worked in support for
both mystery key and private key affirmation, performs customized encryption of all data, and
can read an ebb and flow SSH configuration.Use this module when yourperl application needs to
interface with a SSH-guaranteed host.DBD::mysql "is theperl 5 database Interface driver for the
MySQLdatabase. In a manner of speaking: DBD::mysql is an interface among the
perlprogramming language and the MySQLprogramming Programming interface that goes with
the MySQL relational database managementsystem"( CPAN, 2017).
In your analysis, demonstrate how data center.
$main = Win32::GUI::Window->newnew(-width => 100, -height =>100);
use Win32::GUI();
$main = Win32::GUI::Window->new(
-name => 'Main',
-width => 100,
-height => 100,
);
$main->Add Label(-text => "Scripting with Perl CSS260");
$main->ShowShow ();
Win32Win32::GUI::Dialog();
sub Main_Terminate {
-1;
}
#Using win32::GUI
output
These modules are profitable for keeping up and interfacing with thedatabase; making it
easier to invigorate and take off changes if require. DBI requires adatabase driver module to chat
with thedatabase. The driver module handles most of the bits of knowledge about interfacing
with and talking with thedatabase.
#DATA SOURCE NAME
$dsn = "dbi:mysql:$database:localhost:3306";
#perl DBI CONNECT
$DBIconnect = DBI->connect($dsn, $user, $password);
Describe how you you have identified.?
Installing a newmodule can be as simple astyping perl -MCPAN -e 'install
In the terminal;select the module youwant typecapnm DBD::mysqlcpanm
Net::SSHWin32::GUI if modules does notwant to install you can force it; by typing
cpanm -f install Win32::GUI
Syntax
Executessystem commands to retrievesystem metrics like CPU utilization
# Global variables to gather system data
chomp(my $hostName = `hostname`);
chomp(my $operatingSystem = `uname -s`);
chomp(my $kernelName = `uname -s`);
chomp(my $kernelVersion = `uname -v`);
chomp(my $kernelRelease = `uname -r`);
chomp(my $machineHwName = `uname -m`);
chomp(my $hardwarePlatform = `uname -i`);
chomp(my $processorType = `uname -p`);
# Capture memory statistics
chomp(my $vmMemoryStats = `vmstat`);
# Determine memory utilization
chomp(my $memoryStats = `free`);
# Determine disk utilization
my @diskUtilization = `df -k`;
Reads informationfrom a flat file and then inserts into adatabase
#!/usr/local/bin/perl
open (MYFILE, 'data.txt');
while (<MYFILE>) {
chomp;
print "$_\n";
}
close (MYFILE);
open (MYFILE, 'data.txt');
while (<MYFILE>) {
Inside the loop, then use the
chomp
chomp;
print "$_\n";
Finally close the filehandle tofinish out theprogram.
#OUTPUT
Connects toadatabase and retrieves reporting information
#subroutine
sub Print_DB_Table1 {
my($dbh) = $_[0];
my($dbTable) = $_[1];
my@data;
my$serverName;
my$ipAddress;
my$serverStatus;
my$cpuUtilization = 0;
my$memoryUtilization = 0;
my$diskFree = 0;
# Plan question...
my$sth = $dbh->prepare("SELECT * FROM $dbTable")
or, then beyond words "get ready proclamation: " . $dbh->errstr;
# Execute the question...
$sth->execute( )
or, then beyond words "execute articulation: " . $sth->errstr;
# Print out thetable headers
print("Server Name \t IP \t\t Status \t CPU \t Memory \t Free-Disk\n");
# segments begin at 1.
$sth->bind_col(1, \$serverName);
$sth->bind_col(2, \$ipAddress);
$sth->bind_col(3, \$serverStatus);
$sth->bind_col(4, \$cpuUtilization);
$sth->bind_col(5, \$memoryUtilization);
$sth->bind_col(6, \$diskFree);
# Perused of the records from the giventable and print them out
while (@data = $sth->fetchrow_array( )) {
#print("@data");
print("$serverName \t");
print("$ipAddress \t");
print("$serverStatus \t");
on the off chance that (characterized $cpuUtilization && length $cpuUtilization > 0) {
print("$cpuUtilization \t");
on the off chance that (characterized $memoryUtilization && length $memoryUtilization > 0) {
print("$memoryUtilization \t\t");
on the off chance that (characterized $diskFree && length $diskFree > 0) {
print("$diskFree \t");
print("\n")
on the off chance that ($sth->rows == 0) {
print("No columns intable $dbTable.\n\n");
$sth->finish;
print("\n");
Works Cited
CPAN (2017) DBD-mysql http://search.cpan.org/~michielb/DBD-mysql-
4.041/lib/DBD/mysql.pm
Client-side Scripting Features (2007) http://www.sqa.org.uk/e-
learning/ClientSide01CD/page_22.htm
WIN32(n.d) Win32::GUI http://perl-win32-gui.sourceforge.net/cgi-bin/index.cgi
About tech (2017) how to read a file and write files in Perl
http://perl.about.com/od/perltutorials/a/readwritefiles.htm