Pi statistics

Idea for pi statistics script

Suggested monitor script to be run 1 time per day

#!/bin/bash

# Get portnumber identifier
PORTNUMBER=`/home/pi/genport.sh`

# Number of unscheduled reboots logged
USREBOOT=`last reboot | grep reboot | grep -v 05 | wc -l`

# Number of scheduled reboots logged
SREBOOT=`last reboot | grep reboot | grep 05 | wc -l`

# Bytes used on the root partition
USEDBYTES=`df | grep ' \/$' | awk '{print $3}'`
# Bytes free on the root partition
FREEBYTES=`df | grep ' \/$' | awk '{print $4}'`

# Check temperature in C
PITEMP=`/opt/vc/bin/vcgencmd measure_temp | sed "s/'//g" | cut -c 6- | sed "s/C//g"`

# Time of last boot (in unix time)
BOOTTIME=$(date "+%s" -d "`cut -f1 -d. /proc/uptime` seconds ago")

# Time now (in unix time)
NOWTIME=`date "+%s"`

# Uptime in seconds
UPTIME=`cat /proc/uptime | awk '{print $1}'`

# Check if a WAN interface is in monitor mode - required for package capture (1 for yes, 0 for no)
MMODE=`iwconfig 2>&1 | grep -q -i monitor  && echo "1" || echo "0"`

# New logfiles currently on pi - should be between 1-7 on a functioning pi
NEWLOGS=`find /home/pi/logs -type f -mmin -30 | wc -l`

# Comma separated output of the above
echo $PORTNUMBER,$USREBOOT,$SREBOOT,$USEDBYTES,$FREEBYTES,$PITEMP,$BOOTTIME,$NOWTIME,$UPTIME,$MMODE,$NEWLOGS

# example output
# 50244,1,17,1438652,12985868,54.8,1574132727,1574160221,27494.92,1,2