Script that shows the statistics of computer ( linux e osx )
About 2 years ago, needing to easily check the situation of a computer with Ubuntu via shell and with a single command, I started writing a bash script that would take control of all the parameters of the computer.
Very often you do not want to install different GUI for controlling temperature, cpu frequency, free space, ram, data transferred, information about the kernel and the distro in use etc. etc., or just not showing all the data you want within a single program.
A unix shell provides enormous potential, and can be obtained, at will, all the information you want, and maybe put them together for viewing screen, send them on a web page or whatever.
in this case, Having perfected the script on Ubuntu, I copied OSX on an iBook G4 and I slowly adapted to OSX, bringing it to show almost the exact same information that is shown on Ubuntu Linux.
Here's the source code, tested both with athlon athlon xp with that 64 (Ubuntu) that with iBook G4 (OSX).
Probably, in the version for OSX, temperatures are not detected correctly with an Intel, but I can not verify.
– Ubuntu
#script stats #monitor your hardware and software data in ubuntu #copyright flapane.com 2009 b = `uname-r` | grep 'model name' | sed -e 's/.*: //' | tail --lines=1` e=`sensors | grep 'temp2' | sed -e 's/.*: //' | awk '{print $1}'` #WITHOUTLMSENSOR e=`cat /proc/acpi/thermal_zone/THRM/temperature | grep 'temperature' | sed-e 's / ® / /' ` | grep 'Byte RX' | awk '{print $3 $4}'` h=`/sbin/ifconfig eth0 | grep 'Byte RX' | awk '{print $7 $8}'` i=`free -m | grep 'buffers/cache' | awk '{print $3}'` j=`cat /proc/meminfo | grep 'MemTotal' | awk '{print $2}'` k=`uptimemod` l=`cat /proc/cpuinfo | grep 'cpu MHz' | sed -e 's/.*: //' | tail --lines=1` x=`expr $i \/ 1024` \/ 1024` m=`dmesg | grep-i-F 'processor.' | sed -e 's/.*] //' | tail --lines=1` n=`sensors | grep 'fan1' | sed -e 's/.*: //' | awk '{print $1}'` | grep 'at' | sed -e 's/.*: //' | awk '{print $1}'` p=`cat /sys/class/hwmon/hwmon0/device/pwm2` q=`df -h | sed -e 's/^/-=[ /G; s/$/ ]=-/g' | egrep-e-e hd sd ` "PC statistic" echo "-=[ Kernel info: $b ]=-" echo "-=[ $F ]=-" echo "-=[ CPU Info: $A ]=-" echo "-=[ CPU Full: $M ]=-" echo "-=[ CPU Mhz: $The ]=-" echo "-=[ CPU Temp.: $and ]=-" echo "-=[ CPU Vcore: $the ]=-" echo "-=[ CPU Fan: $n (pwm:$P)]=-" echo "-=[ Incoming/Outgoing: $G / $h ]=-" echo "-=[ Used/Total memory: $i MB / $and MB ]=-" echo "-=[ File systems: ]=-" echo "$q" echo "-=[ $K ]=-"
(uptimemod)
#!/bin / bash # created by masterminds a=`cat /proc/uptime | cut -d " " -f1` b=`echo $a | cut -d "." -f1` e=`expr $b \/ 86400` f=`expr $b \% 86400` g=`expr $f \/ 3600` h=`expr $f \% 3600` i=`expr $h \/ 60` \% 60` if [ $and == 0 ] then if [ $g == 0 ] then echo "Uptime: $the min, $j sec" else echo "Uptime: $g hour, $the min, $j sec" fi else if [ $g == 0 ] then echo "Uptime: $e day, $the min, $j sec" else echo "Uptime: $e day, $g hour, $the min, $j sec" be
– MAC OSX
#!/bin/bash #Mac os stats from my old linux stats script http://peek.snipurl.com/2zgm9 #author flapane (www.flapane.com) #last rev. 9-Sep-08 #get temps by djbidi@gmail.com it probably don't gets temp from Intel cpus sensors=`ioreg -n IOHWSensor | awk '/location/ || /current-value/ || /"type"/' | sed -e 's/[^"]*"//' -e 's/" =//' -e 's/location//' -e 's/type//' -e 's/"//g' | awk '{ if ((NR % 3) == 0) print $0; else printf $0 " " }'` #get other datas sysprofhw=`system_profiler SPHardwareDataType` sysprofpow=`system_profiler SPPowerDataType` up=`uptime` wire=`top -l 1 | grep PhysMem | awk '{print $2}' | sed -e 's/M.*//'` act=`top -l 1 | grep PhysMem | awk '{print $4}' | sed -e 's/M.*//'` netstat=`netstat -ib | grep en1` a=`echo "$sysprofhw" | awk '/Machine Name/ || /Machine Model/ || /CPU Type/' | But s /[^:]*: //' | awk '{printf $0 " " }'` b=`uname -r` c=`echo "$sysprofhw" | grip CPU | grip Speed | awk '{print $3}'` d=`echo "$sensors" | grep 'temperature' | awk '{ for(i=1;I<5;i ) if ($i=="current-value") $(i+1)=((( (($(i+1) / 2^13) - ($(i+1) / 2^13) % 1 ) / 2^3) - .5)" Ct"); print $0 }' | sed -e 's/current-value //' -e 's/temperature//' | grip CPU | awk '{print $1 $2}'` e=`system_profiler SPSoftwareDataType | grip Mac | awk '{print $6}'` f=`echo "$netstat" | awk '{print $7}' | sed 1q` g=`echo "$netstat" | awk '{print $10}' | sed 1q` mbytesin=`expr $f \/ 1024000` mbytesout=`expr $g \/ 1024000` h=`echo "$wire+$act" | bc` j=`system_profiler SPHardwareDataType | grip Memory | awk '{print $2}'` k=`expr $j \* 1024` l=`echo "$sensors" | grep 'temperature' | awk '{ for(i=1;I<5;i ) if ($i=="current-value") $(i+1)=((( (($(i+1) / 2^13) - ($(i+1) / 2^13) % 1 ) / 2^3) - .5)" Ct"); print $0 }' | sed -e 's/current-value //' -e 's/temperature//' | grip GPU | awk '{print $1 $2}'` m=`echo "$sensors" | grep 'temperature' | awk '{ for(i=1;I<5;i ) if ($i=="current-value") $(i+1)=((( (($(i+1) / 2^13) - ($(i+1) / 2^13) % 1 ) / 2^3) - .5)" Ct"); print $0 }' | sed -e 's/current-value //' -e 's/temperature//' | grep BATTERY | awk '{print $1 $2}'` n=`echo "$sensors" | grep -v 'temperature' | awk '{ for(i=1;I<5;i ) if ($i=="current-value") $(i+1)=(substr((($(i+1)/2^16)"\T"),1,8)); print $0 }' | sed -e 's/current-value //' | grip CORE | awk '{print $1}'` o=`echo "$sysprofpow" | Full grip | grip Charge | awk '{print $5}'` p=`echo "$sysprofpow" | grep Remain | awk '{print $4}'` #shows airport name #q=`dmesg | grip Active | But q | awk '{print $4}'` #upday=`echo "$up" | awk '{ print $3,$4 }' | awk -F, '{ print $1 }'` #uphour=`echo "$up" | awk '{ print $5 }' | sed -e 's/:.*//'` #upmin=`echo "$up" | awk '{ print $5 }' | but it's /'.*: *'// | sed -e 's/,.*//'` uptotal=`uptime | awk ' $4 ~ /mins/ { d=0; h=0; m=$3; exit } $4 ~ /day/ { d=$3; split($5,A,":"); h=a[1]; m=a[2]; exit } { d=0; split($3,A,":"); h=a[1]; m=a[2]; exit } END { printf("-=[ Uptime: %d day%s, %d hours, %d mins ]=-n", D, (d == 1 ? "" : "S"), h, M) } '` #echo stats echo "PC statistic" echo "-=[ Kernel info: Darwin $b ]=-" echo "-=[ Mac OS X $e ]=-" echo "-=[ CPU Info: $a @$c Ghz ]=-" echo "-=[ CPU Temperature: $D ]=-" echo "-=[ CPU Vcore: $n V ]=-" echo "-=[ GPU Temperature: $The ]=-" echo "-=[ Battery Temperature: $M ]=-" echo "-=[ Battery Capacity: $p on $o mAh ]=-" echo "-=[ Incoming/Outgoing wlan: $mbytesin MB / $mbytesout MB ]=-" echo "-=[ Used/Total memory: $h MB / $k MB ]=-" echo "$uptotal"
Free to change, improve and adapt the code, while quoting the author.
Scripts can also download the solito osx/linux repository
These are the sample output:
Ubuntu con Athlon XP:
PC statistic
-=[ Kernel info: 2.6.22-14-386 ]=-
-=[ Ubuntu 7.10 ]=-
-=[ CPU Info: AMD Athlon(tm) ]=-
-=[ CPU Full: Detected 2004.568 MHz processor. ]=-
-=[ CPU Mhz: 1404.000 ]=-
-=[ CPU Temp.: +36.0°C ]=-
-=[ CPU Vcore: +1.425 ]=-
-=[ CPU Fan: 3590 (pwm:15)]=-
-=[ Incoming/Outgoing: (29.2MB) / (6.3MB) ]=-
-=[ Used/Total memory: 156 MB / 504 MB ]=-
-=[ File systems: ]=-
-=[ /dev/sda2 6,0G 4,7G 1,1G 82% / ]=-
-=[ /dev/sda1 180G 83G 98G 46% /media/sda1 ]=-
-=[ /dev/hda1 38G 2,6G 35G 7% /media/hda1 ]=-
-=[ Uptime: 3 hour, 27 min, 38 sec ]=-
OSX con iBook g4
PC statistic
-=[ Kernel info: Darwin 8.11.0 ]=-
-=[ Mac OS X 10.4.11 ]=-
-=[ CPU Info: iBook G4 PowerBook6,7 PowerPC G4 (1.5) @1.33 Ghz]=-
-=[ CPU Temperature: 50.5C ]=-
-=[ CPU Vcore: 1.12242 V ]=-
-=[ GPU Temperature: 51.75C ]=-
-=[ Battery Temperature: 29.5C ]=-
-=[ Battery Capacity: 3840 on 4013 mAh]=-
-=[ Incoming/Outgoing en1: 819 MB / 77 MB ]=-
-=[ Used/Total memory: 364 MB / 1024 MB ]=-
-=[ Uptime: 3 days, 7 hours, 35 mins ]=-