Hi Monks,
I have mysql health chek script on my local machine. I run the script which connects to a remote mysql databases and fetches mysql variables.However i want to fetch the OS parameters like free memory,total RAM of the remote machine.Both the local and host machine are linux based.I have read abt NET::SSH on CAPN however i was unable to find a simple script which shows me the commands or steps to do the connection.Please let me know which NET::?? module to use.Can anybody add the connection code to my script. I would really appreciate this.
# Health check the health of a mysql server.
use strict; use warnings; use Getopt::Long; use DBI; # -- # Print out the usage message # -- sub usage { print " MySQL Health Check Script\n"; print " Maintained By DataVail.com\n"; print " Important Usage Guidelines\n"; print " perl MysqlHC.pl -H <host> -u <user> -p <password> -role <s +erver_role>\n"; print " --role <OLTP,Read-slave,Reporting,Datawarehouse> \n" +; print " Optional parameters:\n"; print " --port <port> \n"; } $|=1; # -- # Parse arguments and read Configuration # -- my ($host, $user, $password, $port, $role, $help); GetOptions ( 'host=s' => \$host, 'H=s' => \$host, 'user=s' => \$user, 'u=s' => \$user, 'password=s' => \$password, 'p:s' => \$password, 'port=i' => \$port, 'role=s' => \$role, 'help' => \$help, ); if (!$host || !$user || !$role || !$help eq '') { usage(); exit(1); } if (!$port) { $port = 3306; } sub var { my $statement; if ($MySQLVersion =~ /^3.*|^4.*/ ) { $statement = 'show variables'; } elsif ($MySQLVersion =~ /^5\.0.*/ ) { $statement = 'show global variables'; } elsif ($MySQLVersion =~ /^5\.[1-9].*|^6.*/ ) { $statement = 'Select * from information_schema.global_variable +s order by 1'; }; # print $statement,"\n"; my $sth = $dbh->prepare($statement); $sth->execute(); while (my ($keyword, $value) = $sth->fetchrow_array()) { # print $keyword,"=",$value,"\n"; $variables{lc($keyword)}=lc($value); } $sth->finish(); } sub stat { my $statement; if ($MySQLVersion =~ /^3.*|^4.*/ ) { $statement = 'show status'; } elsif ($MySQLVersion =~ /^5\.0.*/ ) { $statement = 'show global status'; } elsif ($MySQLVersion =~ /^5\.[1-9].*|^6.*/ ) { $statement = 'Select * from information_schema.global_status o +rder by 1'; }; # print $statement,"\n"; my $sth = $dbh->prepare($statement); $sth->execute(); while (my ($keyword, $value) = $sth->fetchrow_array()) { # print $keyword,"=",$value,"\n"; $status{lc($keyword)}=lc($value); } $sth->finish(); } system_memory=`cat /proc/meminfo |grep -w MemTotal |awk '{print $2}'` total_system_memory=$(echo "$system_memory * 1024" | bc -l)
Update:
when i ran the script is gave me this error#!/usr/bin/perl -w use strict; use warnings; use Net::SSH qw(ssh); my $user = "abhishek"; my $hostname = "dpsharp"; my $command = "`cat /proc/meminfo |grep -w MemTotal |awk '{print $2} +'`";--->line 9 ssh('user@hostname', $command);
please let me know my mistake When i ran the following code it gives me this errorUse of uninitialized value in concatenation (.) or string at ./ssh.pl +line 9. ssh: hostname: Name or service not known
can anybody help me in this.#!/usr/bin/perl -w use strict; use warnings; use Net::SSH qw(ssh); my $user = "root"; my $hostname = "orarac1"; my $command = "cat /proc/meminfo |grep -w MemTotal |awk '{print \$2} +'"; ssh("$user\@$hostname", "$command"); Host key verification failed.
20080128 Janitored by Corion: Restored original post, update marked and appended as such
In reply to How to connect to remote machine by aalneyperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |