#!/bin/bash # # Poop Organizes Other Poop # v.0.2 by 31d1 # # poops out a nice display of interesting stuff. # display is slightly different depending on OS and config # # should run on mac, linux, BSD, or cygwin # cygwin: requires procps and curl # # Shows: Internal IP(s), WLAN info**, External IP, Host, Uptime, # Mounted Disks, Memory use, CPU use, Battery Info**, # Temperatures*, # # *(F?)BSD only # **mac and linux only # version [ "$1" == "-v" ] && { echo "POOP v.0.2" exit } # help message [ "$1" == "-h" ] && { cat << EOF Usage: poop [option] -l only show local stuff -a show all -v show version number -h display this help message EOF exit } # determine operating system and set paths os=$(uname) cyg=$(echo "$os" | grep 'CYGWIN') bsd=$(echo "$os" | grep 'BSD') [ $cyg ] && os="CYGWIN" [ $bsd ] && os="BSD" [ "$os" != "CYGWIN" ] && { exists=$(which ifconfig) [ "$exists" == "" ] && { [ -x "/sbin/ifconfig" ] && ifpath="/sbin" [ -x "/usr/sbin/ifconfig" ] && ifpath="/usr/sbin" } } echo # NETWORK STUFF [ "$1" != "-l" ] && { # internal IP if [ "$os" == "CYGWIN" ]; then ipconfig | awk '/IP Address/ { printf "INT : " $15 " " }' else if [ "$ifpath" ]; then ifconf=$($ifpath/ifconfig 2> /dev/null | awk '/broadcast/ { printf "INT : " $2 " " }') else ifconf=$(ifconfig 2> /dev/null | awk '/broadcast/ { printf "INT : " $2 " " }') fi if [ "$ifconf" ]; then echo -n "$ifconf" else if [ "$ifpath" ]; then $ifpath/ifconfig 2> /dev/null | awk '/inet / || /encap/' else ifconfig 2> /dev/null | awk '/inet / || /encap/' fi fi fi # wireless network (Mac) [ "$os" == "Darwin" ] && { if [ -x "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport" ]; then /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | awk '/avg/ || / SSID/ {printf $0 }' | awk '{ print "WLAN : " $6 ", S/N " $2 "/" $4 }' else echo system_profiler SPAirPortDataType | grep 'Current' | sed 's/.*Network../WLAN : /' fi } # wireless network (Linux) [ "$os" == "Linux" ] && { wlan=$(/sbin/iwconfig 2> /dev/null | awk '/ESSID/ || /Quality/') [ "$wlan" ] && echo "$wlan" } # external IP extip=$(curl -s --connect-timeout 5 ip.cutup.org) [ $extip ] && echo -n "Ext : $extip " # host [ "$extip" ] && { ihost=$(host $extip 2> /dev/null) if [ "$ihost" ]; then isitthis=$(echo "$ihost" | awk ' /pointer/ { print "HOST : " $5 }') if [ "$isitthis" ]; then echo "$isitthis" else isitthis=$(echo "$ihost" | awk '/Name/ { print "HOST : " $2 }') [ "$isitthis" ] && echo "$isitthis" fi else host=$(nslookup $extip 2> /dev/null | awk '/Name/ { print "HOST : " $2 }') if [ "$host" ]; then echo "$host" else nslookup $extip 2> /dev/null | awk '/name =/ { print "HOST : " $4 }' fi fi } } [ "$1" == "-a" ] && echo # LOCAL STUFF if [ "$1" == "-a" ] || [ "$1" == "-l" ]; then # uptime uptime | sed -e 's/....user.*//' -e 's/.*up/Uptime :/' echo # mounted disks if [ "$os" == "CYGWIN" ]; then df -h | awk '/cygdrive/ || /Filesystem/' else df -lh fi echo # memory if [ "$os" == "Darwin" ]; then top -l 1 | awk '/PhysMem/ {print "Memory : " $8, $9, $10, $11 }' else top -n 1 | grep 'Mem' fi # cpu if [ "$os" == "Darwin" ]; then top -l 2 | grep 'CPU usage' | tail -1 | awk '{print "CPU : " $8, "user " $10, "sys " $12, "idle" }' elif [ "$os" == "BSD" ]; then top -d2 | grep 'CPU states' | tail -1 else top -n 1 | grep 'Cpu' fi # temperatures [ "$os" == "BSD" ] && { tempers=$(sysctl -a hw.sensors 2> /dev/null | awk '/temp/ { print $3, $2, $4, $5, $6, $7, $8 }' | sed 's/,/:/g') [ "$tempers" ] && echo "$tempers" } # battery [ "$os" == "Darwin" ] && { echo system_profiler SPPowerDataType | /usr/bin/awk '/Full/ || /Remaining/ || /Cycle/ { printf }' | sed -e 's/[^:]*/Battery/' -e 's/ *R.*):./\//' -e 's/ *Cycle/ (mAh) Cycle/' } [ "$os" == "Linux" ] && { batt=$(acpi 2> /dev/null) [ "$batt" ] && echo -e "\nBattery: $batt" } fi echo