ArmLUG Forum
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  Home    Help    Search    Calendar    Login    Register  
*
News : September 09, 2010, 07:58:06 PM
+  ArmLUG Forum
|-+  GNU/Linux
| |-+  Web Programming (Moderators: Mesrop, kernel)
| | |-+  PHP Script, to get linux info.
Advanced search
  « previous next »
Pages 1
Author
Topic: PHP Script, to get linux info.  (Read 2988 times)
« on: August 21, 2008, 04:04:22 PM »
kernel Offline
Moderator
Newbie
*****
kernel Posts: 39
346797916
View Profile WWW

Հարգելի բարեկամներ, Linux - ի եւ PHP - ի սիրահարներ.
Այսօր ձեզ եմ ներկայացնում ծրագիր, որի միջոցով կարելի է ստանալ տվյալներ, Linux  օպ. համակարգի մասին.

Ստանում ենք ինֆորմացիա օպրացիոն համակարգի մասին, պրոցեսսորի մասին, հիշողության մասին.
Զգուշացում: լինում են դեպքեր, երբ նշվածներից վերջին երեքը չեն աշխատում.

<?
echo "Get main info<br>";
$a = array();
exec("uname -a ",$a);
$i=0;
$c=count($a);
while($i<$c) {
   echo "<br>".$a[$i];
   $i++;
}
/////////////////////////////////////////////////////      
echo "<br>Get CPU Info<br>";

$ldir = "/proc";
   
$p = parsefile($ldir."/cpuinfo");

$c = count($p);
$i=0;
echo '<table cellpadding="3" cellspacing="0">';
while ($i < $c ) {
    echo "<tr><td><b>".key($p).':</b></td><td> '.$p[key($p)].'</td></tr>';
    next($p);
   $i++;
} // end while
echo "</table>";
////////////////////////////////////////////////////////
echo "Get MEMORY info<br>";
unset($p);
$p = parsefile($ldir."/meminfo");

$c = count($p);
$i=0;
echo '<table cellpadding="3" cellspacing="0">';
while ($i < $c ) {
   echo "<tr><td><b>".key($p).':</b></td><td> '.$p[key($p)].'</td></tr>';
    next($p);
   $i++;
} // end while
echo "</table>";
///////////////////////////////////////////////////////////
function parsefile($file) {
        @$content = file_get_contents($file);
        $info=array();
        foreach( explode("\n",$content) as $line) {
            $pos = strpos($line,":");
            $key = trim( substr($line,0,$pos) );
            $val = trim( substr($line,$pos+1) );
            if ( $key=="") continue;
            $info[$key] = $val;
        }
        return $info;       
    }
   
?>

Ընդունում եմ առաջարկներ եւ նկատողություններ...
Logged

 
Reply #1
« on: August 21, 2008, 06:00:46 PM »
xalyavshik Offline
Sr. Member
****
Linux Registred User #472973 Posts: 385
757487
View Profile WWW Email

սա իմ կոմպը  Cheesy
Quote
Get main info

Linux localhost 2.6.25-14.fc9.i686 #1 SMP Thu May 1 06:28:41 EDT 2008 i686 i686 i386 GNU/Linux
Get CPU Info
processor:   0
vendor_id:   GenuineIntel
cpu family:   6
model:   7
model name:   Pentium III (Katmai)
stepping:   3
cpu MHz:   497.846
cache size:   512 KB
fdiv_bug:   no
hlt_bug:   no
f00f_bug:   no
coma_bug:   no
fpu:   yes
fpu_exception:   yes
cpuid level:   2
wp:   yes
flags:   fpu vme de pse tsc msr pae mce cx8 mtrr pge mca cmov pat pse36 mmx fxsr sse up
bogomips:   996.81
clflush size:   32
Get MEMORY info
MemTotal:   319976 kB
MemFree:   240480 kB
Buffers:   5452 kB
Cached:   52728 kB
SwapCached:   0 kB
Active:   33124 kB
Inactive:   36104 kB
HighTotal:   0 kB
HighFree:   0 kB
LowTotal:   319976 kB
LowFree:   240480 kB
SwapTotal:   655352 kB
SwapFree:   655352 kB
Dirty:   32 kB
Writeback:   0 kB
AnonPages:   11048 kB
Mapped:   11968 kB
Slab:   6004 kB
SReclaimable:   2320 kB
SUnreclaim:   3684 kB
PageTables:   1256 kB
NFS_Unstable:   0 kB
Bounce:   0 kB
CommitLimit:   815340 kB
Committed_AS:   69028 kB
VmallocTotal:   700408 kB
VmallocUsed:   1820 kB
VmallocChunk:   698212 kB
HugePages_Total:   0
HugePages_Free:   0
HugePages_Rsvd:   0
HugePages_Surp:   0
Hugepagesize:   4096 kB

Դավ ջան դուրս եկավ Smiley
Logged

# killall -9 "win PC"
 
Reply #2
« on: August 21, 2008, 06:05:52 PM »
kernel Offline
Moderator
Newbie
*****
kernel Posts: 39
346797916
View Profile WWW

Շատ շնորհակալ եմ.
Ցավոք սրտի, որոշ ինտերնետ սերվերներում չի աշխատեւմ.
Logged

 
Reply #3
« on: August 21, 2008, 11:07:24 PM »
seryoga Offline
Newbie
*
Posts: 43

View Profile

Տենաս բա խի չի աշխատում?
Logged
 
Reply #4
« on: August 21, 2008, 11:10:24 PM »
kernel Offline
Moderator
Newbie
*****
kernel Posts: 39
346797916
View Profile WWW

Երկու հայտնի պատճառներով
1) permission denied
2) file not exists
Logged

 
Reply #5
« on: August 22, 2008, 01:18:49 AM »
xalyavshik Offline
Sr. Member
****
Linux Registred User #472973 Posts: 385
757487
View Profile WWW Email

ես կասեի pretmission denied  Wink
կամ ել հիմնականում chroot-ով են դնում սեռվեռները դրա համար ել այդ ֆայլը մեր համար հասանելի չի լինում  Wink
Logged

# killall -9 "win PC"
 
Print  Pages 1
« previous next »
Jump to: