If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > ping hosts from database

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-26-11, 11:02
ahmenty ahmenty is offline
Registered User
 
Join Date: Apr 2011
Posts: 2
ping hosts from database

I have a php script
I want it to ping list of ips from a databse(using fping) and based on the status of the values to put them in a field(status) into the database(0 if down,1 if up)
i executed tghe script and it gives me this error:
Thread 1 - 17:51:01 26-04-2011 4.2.2.2 alive Couldn't execute query.
I cant see what 's wrong

this is the source of the php script:
Code:
<?php
require_once("conf.php");
$connection1 = mysql_connect($h, $u, $p) or die("Couldn't connect.");


$db_name = "status";
$table_name = "voip";
$connection = mysql_connect($h, $u, $p) or die("Couldn't connect.");
$db = mysql_select_db($db_name, $connection) or die("Couldn't select database.");
$sql = "SELECT ip
        FROM $table_name where thread = '1' ORDER BY ip
                ";
    $result = mysql_query($sql,$connection) or die("Couldn't execute query1...");
    while ($row = mysql_fetch_array($result)) {
                                $ip = $row['ip'];


$comanda = "/usr/bin/fping ". $ip;
$str=exec($comanda);

list($ip, $is, $status) = sscanf($str, "%s\t%s\t%s\n");

$dataa= date("H:i:s d-m-Y");

print "Thread 1 - ";
print $dataa;
print "\t";
print $ip;
print "\t\t";
print $status;
print "\n";



$dbname="status";
$db1 = mysql_select_db($dbname, $connection1) or die("Couldn't select database.");
$sql1 = "UPDATE voip SET status = '$status', lastupdate = '$dataa' WHERE ip = '$ip'";
$result1 = mysql_db_query($dbname,$sql1) or die("Couldn't execute query.");

}
?>
this is the database:
database: status
table: voip
fields: id ip status thread
1 4.2.2.2 1
2 4.2.2.2 1
3 4.2.2.2 1
Reply With Quote
  #2 (permalink)  
Old 04-26-11, 12:11
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
  • Why don't you just print out the $sql value in the die command? that way you can see what's actually being run.
  • Why are the table and database names in variables?
  • Why do you have search odd variable names $comanda $dataa? $sqll
  • Your code is very difficult to read and the indenting is very strange.
  • Is that date format correct for MySQL? I thought it should be YYYY-MM-DD HH:mm.
  • Bits like the following :
    Code:
    print "Thread 1 - ";
    print $dataa;
    print "\t";
    print $ip;
    print "\t\t";
    print $status;
    print "\n";
    can also be shortened into :
    Code:
    print "$dataa\t$ip\t\t$status\n";
__________________
Mike
Reply With Quote
  #3 (permalink)  
Old 04-26-11, 16:03
ahmenty ahmenty is offline
Registered User
 
Join Date: Apr 2011
Posts: 2
thx

Yes..it was the date problem
it works fine now
Thank you very much
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On