Gather Linux Uptime (Multiple servers)
By: Daniel
In a response to a comment requesting information to get uptime of multiple servers, here is some sample code. This code can be expanded even more using a database to store website addresses, but for basic purposes I am just looping through an array of websites.
$sites = array('wlscripting.com'); // Create a list of sites to check foreach($sites as $site) { // Loop through each site and get uptime $ch = curl_init(); // Initiate curl session curl_setopt($ch, CURLOPT_URL, 'http://'.$site.'/linuxUptime.php'); // Set the URL of the uptime script curl_setopt($ch, CURLOPT_HEADER, 0); // Disable header output curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // Return data as a string instead of output directly $data=curl_exec($ch); // Execute curl commands curl_close ($ch); // Close the curl session echo $site.': '.$data.'<br />'; // Output value returned from the linuxUptime.php file } // End server loop
This code loops through the $sites array to determine which sites to gather information from.
On every server you wish to check the uptime, create a file in the root of the domain called: linuxUptime.php. In this file you should include the code found in the Linux Uptime tutorial and only echo out the uptime. Anything that is output in the linuxUptime.php file will show up in the above output.
Enjoy!




















