OK, Im back, this time with the small newbie script Ive put together. Ive removed the $ENV{} for roots homedir and added the full path instead but I still get error att line 43(marked with comment and <---). Ive search on the site but cant seem to get any clues on whats going wrong here.

#!/usr/bin/perl # # getsysinfo.pl - via ssh, get systeminformation about servers. # Note: This script depends on DSA/RSA key authentication # as we dont want passwords in the actual script so # you need to make sure you got this set up correctly # before this script will work. use DBI; use Net::SSH::Perl; $username = 'root'; %db = ( database => 'sysinfo', hostname => 'localhost', username => 'boogo', password => 'xxxxx'); # Hostnames of servers to check @servers = ('nw04','nw05','gw01'); # Commands for the checks to be executed. %checks = ( "disk" => 'df -h', "mem" => 'free -mot', "pci" => 'lspci -v', "net" => 'ifconfig' ); %results = {}; # Set up mysql connection $dsn = "DBI:mysql:database=$db{'database'}:host=$db{'hostname'}"; $db = DBI->connect($dsn, $db{'username'}, $db{'password'}) or die ("$!\n"); # lets walk the @servers array and do the tests and save results. foreach $server (@servers) { $ssh = Net::SSH::Perl->new($server, debug=>0, identity_files=>["/root/.ssh/id_rsa.pub"], protocol=>'2,1'); $ssh->login($username); # <--- ERROR returned +from cron to root's mailbox while (($key, $value) = each(%checks)) { if (&db_host_exists($server) > 0) { # host already exists in database, lets update it. ($stdout, $stderr, $exit) = $ssh->cmd($checks{$key}); $sth = $db->prepare(qq{ UPDATE servers SET $key='<pre>$stdout</pre>', updated=NOW() }); $sth->execute(); $sth->finish; } else { # host does not exists in database, lets insert it. ($stdout, $stderr, $exit) = $ssh->cmd($checks{$key}); $sth = $db->prepare(qq{ INSERT INTO servers (id, hostname, updated, $key) VALUES ('','$server',NOW(),'<pre>$stdout</pre>') }); $sth->execute(); $sth->finish; } } } # db_host_exists($) - subroutine to check if the host allready # exists in the database. Then we use update, # otherwise insert. # Arguments: $ - hostname to look for sub db_host_exists($) { $result = 0; $sth = $db->prepare(qq{ SELECT * FROM servers WHERE hostname LIKE '%$server%' }); $sth->execute(); if ($sth->rows > 0) { $result = 1; } $sth->finish; return $result; }

Guess you monks will see my error right away.

My cron line looks like this:
0,30 * * * * /root/bin/getsysinfo.pl


/Roger

In reply to Re^4: Perl script in cron by bashi
in thread Perl script in cron by bashi

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.