Код: Выделить всё
#!/bin/sh
#
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <cytopia@everythingcli.org> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return cytopia
# ----------------------------------------------------------------------------
#
# ---------------------------------- Global Variables -------------------------- ------- #
# Colors
GREEN="\033[32m"
YELLOW="\033[33m"
RED="\033[31m"
OFF="\033[0m"
# ---------------------------------- Misc Function ----------------------------- ----- #
#
# Prequisites,
# * check if this script is run by root
# * check if smartctl is installed
#
check_requirements()
{
# Check if we are root
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# Check if smartctl exists on the system
command -v smartctl >/dev/null || { echo "smartctl not found. (install sysutils/smartmontools)"; exit 1; }
}
#
# Colorize output of temperature (all platforms)
#
colorize_temperature()
{
temp=$1
case $temp in
# no temperature obtained
''|*[!0-9]*)
temp="n.a."
;;
# temperature is obtained
*)
if [ $temp -gt 40 ]; then
temp="${RED}${temp} C${OFF}"
elif [ $temp -gt 30 ]; then
temp="${YELLOW}${temp} C${OFF}"
else
temp="${GREEN}${temp} C${OFF}"
fi
;;
esac
echo $temp
}
# ---------------------------------- Generic Disk Function --------------------- ------------- #
#
# Get all devices that are attached to the system
#
get_attached_devices()
{
DEVS=`sysctl kern.disks | awk '{$1=""; ;print $0}' | awk 'gsub(" ", "\n" )' | tail -n500 -r | sed '/^cd[0-9]/d'`
#DEVS=`bla`
echo $DEVS
}
get_disk_bus()
{
dev=$1
bus=`cat /var/run/dmesg.boot | grep "${dev} at" |grep target | awk '{pri nt $3}'`
echo $bus
}
get_disk_size()
{
dev=$1
size=`diskinfo -v /dev/${dev} | grep bytes | awk '{printf "%.2f\n",($1/( 1024*1024*1024))}'`
echo $size
}
get_disk_speed()
{
dev=$1
speed=`cat /var/run/dmesg.boot |grep ${dev}: | grep transfers | awk '{pr int $2};'`
echo $speed
}
get_disk_number()
{
dev=$1
disk_num=`echo ${dev} | sed 's/[^0-9]*//g'`
echo $disk_num
}
# ---------------------------------- ATA-Device Functions ---------------------- ------------ #
get_ata_disk_name()
{
dev=$1
name=`cat /var/run/dmesg.boot |grep ${dev}: | grep "<"|grep ">" | awk ' gsub(/<|>/, "\n");' | awk 'NR==2'`
echo $name
}
get_ata_disk_temp()
{
dev=$1
temp=`smartctl -d atacam -A /dev/${dev} | grep Temperature_Celsius | awk '{print $10}'`
echo $temp
}
# ---------------------------------- CISS-Device Functions --------------------- ------------- #
get_ciss_disk_name()
{
smartctl=$1
name=`echo "${smartctl}" | grep "Device Model" | awk '{$1=$2=""} {sub(/^ [ \t]+/, ""); print;}'`
firm=`echo "${smartctl}" | grep "Firmware" | awk ' {$1=$2=""} {sub(/^[ \ t]+/, ""); print;}'`
echo "$name $firm"
}
get_ciss_disk_temp()
{
smartctl=$1
temp=`echo "${smartctl}" | grep Temperature_Celsius | awk '{print $10}'`
echo $temp
}
# ---------------------------------- Main Entry Point -------------------------- -------- #
# Check if script can be run
check_requirements
# Loop through all attached devices
for dev in `get_attached_devices`
do
size=`get_disk_size ${dev}`
bus=`get_disk_bus ${dev}`
speed=`get_disk_speed ${dev}`
# check for HP Smart Array controllers
#if [ $bus == "ciss*" ]; then
# devnum=`get_disk_number ${dev}`
# smartctl=`smartctl -a -T permissive -d cciss,${devnum} /dev/${bu s} 2> /dev/null`
# name=`get_ciss_disk_name "${smartctl}"` # preserve newlines by u sing "
# temp=`get_ciss_disk_temp "${smartctl}"`
# echo "smartctl -a -T permissive -d cciss,${devnum} /dev/${bus} 2 > /dev/null" # debug
#else
name=`get_ata_disk_name ${dev}`
temp=`get_ata_disk_temp ${dev}`
#fi
temp=`colorize_temperature ${temp}`
echo -e "$temp\t${dev}\t${name} (${size}G)"
#echo -e "$temp\t${bus}:${dev}\t${speed}\t${name} (${size}G)"
done
#eof
переделал для себя:hddtemp
51 C ada0 SAMSUNG SP0802N TK200-04 (74,56G)
48 C ada1 WDC WD800BB-22JHC0 05.01C05 (74,53G)
Код: Выделить всё
# hddtemp | awk '{print $1, $4, $5}'
51 SAMSUNG SP0802N
48 WDC WD800BB-22JHC0
Код: Выделить всё
<?php
/**
* hddtemp sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.hddtemp.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from hddtemp
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @author T.A. van Roermund <timo@van-roermund.nl>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class HDDTemp extends Sensors
{
/**
* get the temperature information from hddtemp
* access is available through tcp or command
*
* @return array temperatures in array
*/
private function _temperature()
{
$temp = 0;
if (CommonFunctions::executeProgram("hddtemp", $temp)) {
$dev = new SensorDevice();
$dev->setName("HDD");
$dev->setValue($temp);
$dev->setMax(" ");
$this->mbinfo->setMbTemp($dev);
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
}
}
как правильно записать команду на выполнение?if (CommonFunctions::executeProgram("hddtemp", $temp)) {