[PC-BSD Dev] Simple 'about' console script

Fabrizio Parrella fabrizio at bibivu.com
Thu Mar 28 05:41:26 PDT 2013


On 03/28/2013 05:35, Yuri Momotiuk wrote:
>
>
> 2013/3/27 Fabrizio Parrella <fabrizio at bibivu.com 
> <mailto:fabrizio at bibivu.com>>
>
>     I really like it.
>
>     On the General information, can you add:
>      - Uptime
>
>
> Added
GREAT !!
>
>      - Used/Free memory (can give you my script for this if you want)
>
>
> Seems like added. There is several methods of free memory amount 
> calculation.
There are, this is my PERL way to do it

@tmp=split / /m,`sysctl vm.stats.vm.v_free_count`;
$v_free_count=$tmp[1];
@tmp=split / /m,`sysctl vm.stats.vm.v_inactive_count`;
$v_inactive_count=$tmp[1];
@tmp=split / /m,`sysctl vm.stats.vm.v_cache_count`;
$v_cache_count=$tmp[1];
@tmp=split / /m,`sysctl vm.stats.vm.v_page_count`;
$v_page_count=$tmp[1];
@tmp=split / /m,`sysctl hw.pagesize`;
$page_size=$tmp[1];
$usg=(($v_page_count-$v_free_count-$v_inactive_count-$v_cache_count)*$page_size)/1024;
print "$usg\n";

and this is the swap usage info

$swapinfo = `swapinfo`;
@temp1 = split /^/m, $swapinfo;
$temp2 = @temp1[1];
$temp2 =~ s/,//g;
@line = split /\s+/, $temp2;
$swap = $line[2];
print "$swap\n";

>      - Running/Current Desktop Env (if any)
>
>
> Added
GREAT !
>
>      - Does it show multi CPUs ?
>
>
> Added
GREAT !
this is my script to catch the usage (might be better ways to do it, not 
even sure you want to add this to your script)
foreach $_ (`iostat -odICw 1 -c 2 cpu | grep -v us | grep -v cpu`)
{
     ($null, $cpuus, $cpuni, $cpusy, $cpuin, $cpuid) = split(/\s+/);
}
print "$cpuus\n";
print "$cpusy\n";
>
>     On the Network information can you add:
>      - network card name (eth0, etc...)
>      - DNS
>      - Gateway
>      - DHCP or not
>
>
> Hmm.. Currently sed/awk kung fu for parsing this is too hard for me
This is my way to get the IPs (PHP)
function getIPs($withV6 = false) {
     $ips    = array();
     $return    = false;
     preg_match_all('/inet'.($withV6 ? '6?' : '').' ([^ ]+)/', 
`/sbin/ifconfig`, $ips);
     if(isset($ips[1]) && is_array($ips[1]) && count($ips[1])>0){
         $return = array();
         foreach($ips[1] as $ip){
             if(!in_array($ip, array('127.0.0.1','0.0.0.0'))){
                 $return[] = $ip;
             }
         }
     }
     return $return;
}

I am not sure what would be the "preg_match_all" in your language, but 
in other words is a regular expression on the "ifconfig"

for DNS:
cat /etc/resolv.conf

for router:
grep defaultrouter /etc/rc.conf

when parsing for DNS and Router remove the lines that start with "#"


>
> To get last script you can use subversion:
> svn co 
> https://subversion.assembla.com/svn/pcbsd-extras/trunk/experimental/src-sh
>
> PS
> Does somebody how to determine the current OS (PC-BSD or TrueOS). 
> Maybe some file flag?

Maybe you can try to parse UNAME ?
> -- 
> Best regards, Yuri Momotyuk 

Anyway, great Job
Fabry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pcbsd.org/pipermail/dev/attachments/20130328/dde668ea/attachment.html>


More information about the Dev mailing list