Sunday, December 8, 2013

PHP script for showing computer info

For those wanting to print out information about their server to a web page: I designed the following php script to do that on a Linux server.

 <?php  
      //Removes everything before the first ':' character, meant to get information from /proc/cpuinfo  
      function extractCPUInfoLine($inputString)  
      {  
           return trim(substr($inputString, strpos($inputString, ':') + 1));   
      }  
      //Returns an array of info for the processor  
      function getCPUInfo()  
      {  
           $cpufile = file("/proc/cpuinfo");  
           $memFile = file("/proc/meminfo");  
           $cpuinfoArray = array();  
           $cpuinfoArray["cpu"] = extractCPUInfoLine($cpufile[4]);  
           $cpuinfoArray["speed"] = extractCPUInfoLine($cpufile[7]) . " Mhz";  
           $cpuinfoArray["cache"] = extractCPUInfoLine($cpufile[8]);  
           $cpuinfoArray["memory"] = extractCPUInfoLine($memFile[0]);  
           return $cpuinfoArray;   
      }  
 ?>  

 <html>  
      <head>  
           <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">  
           <title>Server Info</title>  
           <link rel="stylesheet" type="text/css" href="style.css">  
      </head>  
      <body>  
           <h2>About This Server</h2>  
           <?php  
                $cpuInfoArray = getCPUInfo();  
                print "          <table>  
                <tr>  
                     <td>CPU</td>  
                     <td>" . $cpuInfoArray["cpu"] . "</td>  
                </tr>  
                <tr>  
                     <td>CPU Speed</td>  
                     <td>" . $cpuInfoArray["speed"] . "</td>  
                </tr>  
                <tr>  
                     <td>Memory</td>  
                     <td>" . $cpuInfoArray["memory"] . "</td>  
                </tr>  
                <tr>  
                     <td>Cache</td>  
                     <td>" . $cpuInfoArray["cache"] . "</td>  
                </tr>  
                <tr>  
                     <td>Total disk space</td>  
                     <td>" . number_format(disk_total_space("/home") / (1024 * 1024 * 1024), 3) . " Gb</td>  
                </tr>  
                <tr>  
                     <td>Free disk space</td>  
                     <td>" . number_format(disk_free_space("/home") / (1024 * 1024 * 1024), 3) . " Gb</td>  
                </tr>  
           </table>";  
           ?> 
      </head>  
 </html>  



This script will print out the CPU type, speed, memory size, cache size and total and available disk space.

The trick is that within most Linux systems there are files under the /proc directory, such as procinfo and meminfo, which tells you information about your computer's cpu and memory. Getting basic computer info is a matter of reading those files.

Monday, January 14, 2013

Why Free Software Will Sell Our Kids Short


A petition to the White House, asking the Obama administration to promote the use of Free Software, has recently received 3,000 signatures. The petition advocates that schools should be encouraged to use free software and the Linux operating system instead of "mysterious and opaque" proprietary software, however the action this petition proposes will be detrimental to our children's future in the growing digital economy.



Linux was created by Finnish computer hacker Linux Torvolds in the early 1990s. The operating system Linux was an unlicensed copy of an industry operating system called Unix, created by Bell Labs in the 1960s. Unix was sold to large corporations and banks, which made it prohibitively expensive to a young computer hacker. So Mr. Torvolds created his copy in his spare time. Today Linux has become a favorite operating system of hackers world wide and lies at the core of knockoff smartphone brands like Android.

The main problem with Linux, and free software in general, is quality. In 2009 Microsoft invested nearly $9 Billion in research and development. By contrast free software is developed by hackers and computer enthusiasts in their spare time. It may be difficult for most people to understand, especially those who choose to pirate their software, but programing software is a very expensive and time consuming process. How can free software measure up to the standards of large American companies that employ college graduates? The only two outcomes of Free Software is that it is either substandard or illegal.

Assuming Linux is both high quality, legal and free where is it? I can guarantee you that no device in my house runs Linux and we have 3 computers. If you walk into a store, where can you buy a Linux PC? Speaking of which, where is Linux in advertising? You don't see any Mac Vs. PC Vs. Linux ads on TV (by the way I have no preference to either Macs or PCs, I think they both have their distinct uses). The reason for this is that Free Software doesn't have a business model. You can't make money just giving away software. Without a business model you don't see advertising or a presence in retail outlets. Without a business model free software has no incentive to serve its customers like proprietary software does. Linux is not as great as Windows or Apple because the lack of business model doesn't provide any incentive to give the customer a great product.

The lack of a business model in Free Software is detrimental to its users. I decided to install Linux on an old Laptop I had to see what our nations' kids would be getting into. I did my research and found a version that was touted as being user friendly for beginners: Ubuntu Linux. The installation process went alright and when I rebooted my computer it looked very similar to the Apple operating system, but immediately I knew something wasn't right. Apparently I needed to install special drivers for my wireless? It didn't come on the CD apparently. The only way to install the drivers was through an ethernet cable, something I hadn't used in years. I had to dig around in my garage to find the one I used when I had a Desktop. Now here's the problem: why do you need to already be connected to the internet to get an internet connection? Nobody working on Linux realizes this obvious catch-22? My old laptop had an ethernet plug on the side but more modern laptops are so thin that they don't even have one. I worry this is indicative of the quality of the Linux software and that the developers ignore the needs of common computer users.

Assuming you can get Linux working, most worrisome is the fact that Linux doesn't have the software we're used to using. Most businesses use Windows PCs, a lot of creative enterprises and colleges use Macs, I see some retailers at the mall who can swipe credit cards on their iPhones. Linux isn't at any of these places. I did some research and found that common software, used in industry, isn't available. Instead of Microsoft Office or Photoshop, Linux has pale imitators like LibreOffice and Gimp. In our high tech globalized world our kids need skills to compete. How are they supposed to do that if they grow up using something called LibreOffice? A typical job opening today receives hundreds of applicants. HR departments look for any reason to cull that number to about a dozen. If your daughter wants to be a secretary but doesn't have Microsoft Word on her resume how is she even going to get an interview?

Is Linux right for our kids? Linux isn't developed by a single respectable corporation, it doesn't have the investment that being developed by a company would give it, it doesn't have the direction or spirit to compete that a business model would give it, it lacks ease of use and it doesn't support programs used in industry. The core of the problem of Free Software is its decentralized nature. It isn't guided by any one organization and doesn't have the capacity to compete. We know Microsoft will develop great products for business, we know Apple will develop thin innovative new gadgets. Where's the drive behind Linux, what is it there to do? With no one really in charge of Linux how do you know that development will continue? With paid software they always come out with new versions every few years because they know we will buy it. I say don't endanger our kids with the radical notion of depending on Free Software, they deserve quality software.