Home Android Arch Linux Gentoo Linux LibreELEC Github Geo

sysinfo

falls eine HDD oder SSD eingebaut ist, das Programm hddtemp und netcat installieren
ansonsten geht es beim Shell-Skript weiter

Arch Linuxpacman -S hddtemp gnu-netcat
Gentoo Linuxemerge -av hddtemp gnu-netcat

hddtemp starten und beim nächsten Systemstart aktivieren
Arch Linuxsystemctl start hddtemp && systemctl enable hddtemp
Gentoo Linuxrc-update add hddtemp default

das Shell-Script sysinfo erstellen
nano /usr/local/bin/sysinfo.sh

/usr/local/bin/sysinfo.sh

#!/bin/bash
 
echo ""
echo "Linux: `uname -r`"
echo "Uptime: $(uptime | sed 's/.*up \([^,]*\), .*/\1/') "
 
#RAM Usage
echo -n "RAM Usage: "
MEMUSED=$(free | sed -n 2p | awk '{print $(NF-4)}')
MEMTOTAL=$(free | sed -n 2p | awk '{print $(NF-5)}')
echo "$((MEMUSED/1024))MB / $((MEMTOTAL/1024))MB"
 
# CPU Clock
echo -n "CPU Clock: "
if [ -r /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ]; then
   (( CLOCK=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)/1000 ))
   CPUGOVERNOR=$(cat /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor)
   echo "${CLOCK}MHz ($CPUGOVERNOR)"
else
   echo "Clockspeed not available"
fi
 
#CPU Usage
PREV_TOTAL=0
PREV_IDLE=0
i=0
while [ $i -le 1 ]; do
  # Get the total CPU statistics, discarding the 'cpu ' prefix.
  CPU=(`sed -n 's/^cpu\s//p' /proc/stat`)
  IDLE=${CPU[3]} # Just the idle CPU time.
 
  # Calculate the total CPU time.
  TOTAL=0
  for VALUE in "${CPU[@]}"; do
    let "TOTAL=$TOTAL+$VALUE"
  done
 
  # Calculate the CPU usage since we last checked.
  let "DIFF_IDLE=$IDLE-$PREV_IDLE"
  let "DIFF_TOTAL=$TOTAL-$PREV_TOTAL"
  let "DIFF_USAGE=(1000*($DIFF_TOTAL-$DIFF_IDLE)/$DIFF_TOTAL+5)/10"
 
  # Remember the total and idle CPU times for the next check.
  PREV_TOTAL="$TOTAL"
  PREV_IDLE="$IDLE"
 
  # Wait before checking again.
  sleep 1
    i=$(( $i + 1 ))
done
echo -en "CPU Usage: $DIFF_USAGE%\n"
 
 
 
#CPU Frequency
echo ""
totaltime=`awk '{SUM += $2} END {printf("%.0f",SUM/1000)}' /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state`
echo -e "FREQUENCY\tUSED"
SUM=0
awk '
       {
               printf (($1/1000)" MHz \t");
               if ($2 == 0)
               {
                       printf "0 %\n";
               }
               else {
                       SUM+=$2;
                       printf("%.1f%\n",($2/10)/"'"$totaltime"'");
                       }
       }
       END{
#       printf ("Time spent in idle mode is %2.2f %\n",(1-((SUM/1000)/"'"$totaltime"'"))*100);
       }' /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state
 
 
echo ""
echo "Top five processes:"
ps -Ao user,uid,comm,pid,pcpu --sort=-pcpu | head -n 6
 
echo ""
echo "MMC/SD"
if [ -r /dev/mmcblk0 ]; then
   for DEVICE in /dev/mmcblk[0-9]p[0-9]; do
      MOUNT=$(mount | grep ${DEVICE})
      echo " "$MOUNT
   done
else
    echo "  not available"
fi
 
echo "HDD/SSD"
for DEVICE in /dev/sd[a-y]; do
   if [ -c $DEVICE ]; then
      if [ ! -f /usr/sbin/hddtemp ]; then
         echo "  $DEVICE: package hddtemp is not available"
      else
         HDDTEMP=$(nc localhost 7634 | awk -F'|' '{print $3 "   " $4}')
         echo "  $DEVICE: ${HDDTEMP}"°C
      fi
      if [ -e "${DEVICE}1" ]; then
         for PARTITION in $DEVICE[1-99]; do
            PARTTOTAL=$(df -h | grep $PARTITION | awk '{print $(NF-4)}')
            PARTUSED=$(df -h | grep $PARTITION | awk '{print $(NF-3)}')
            PARTMOUNT=$(df -h | grep $PARTITION | awk '{print $(NF-0)}')
            echo "  $PARTITION: ${PARTUSED}B of ${PARTTOTAL}B used and mounted in $PARTMOUNT"
         done
      fi
   fi
done

sysinfo.sh ausführbar machen
chmod +x /usr/local/bin/sysinfo.sh