I want this code to work thru a large cluster and put the rpm information
into a db ,
it all works apart from the foreach loop.

why doesnt my code work ( in particular the foreach loop ) ,

// get hostname
$host = `hostname`;

// get a list of rpms

$rpm_list = `rpm -qa`;

// open a db connection and insert them into the db

include "db.php";


print "working on host : $host\n";

$test = mysql_query ("SELECT * FROM machine_info WHERE host = '$host'");
$test1 = mysql_fetch_object ($test);

print "TEST: $test1->host\n";

if ($test1->host == "")
        {
        print "machine doesnt exists in the db , adding an entry for
$host\n";
        $add_machine_to_table = mysql_query("INSERT INTO machine_info (host)
VALUES ('$host')");
        }

// get the rpm list a line at a time

foreach($rpm_list as $rpm)
        {

        $query = "UPDATE machine_info SET rpm = '$rpm' WHERE host =
'$host'";

        if (!(mysql_query($query)))
                {
                print "Mysql could not do the update query - for host
$host";
                }
        }

------------

i get :

X-Powered-By: PHP/4.0.6
Content-type: text/html


working on host : lxplus038

TEST: lxplus038

<br>
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>
get_rpm_info.php</b> on line <b>29</b><br>


--

many thanx in advance

Neil
:)



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to