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:

#!/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);
when i ran the script is gave me this error
Use of uninitialized value in concatenation (.) or string at ./ssh.pl +line 9. ssh: hostname: Name or service not known
please let me know my mistake When i ran the following code it gives me this error
#!/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.
can anybody help me in this.

20080128 Janitored by Corion: Restored original post, update marked and appended as such


In reply to How to connect to remote machine by aalneyperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.