resmon.sh (1540B)
1 #!/bin/sh 2 3 ## System Resource Monitor Script 4 ## "resmon.sh" 5 ## M. Yamanaka 6 ## email: myamanaka@live.com 7 ## website: csmyamanaka.com 8 ## license: MIT (See included "LICENSE" file for detais) 9 10 #Prints information of interest regarding a user's system 11 12 13 ## 14 ## Information 15 ## 16 17 VOLTEXT="volume" 18 VOLSTAT=$(pactl list sinks | grep "Volume: front-left:" | awk '{print $5}') 19 20 MEMTEXT="RAM" 21 MEMSTAT=$(free -h | grep "Mem:" | awk '{print $3" / "$2}') 22 23 BATTEXT="battery" 24 BATINFO=/sys/class/power_supply/BAT1 25 BATSTAT="$(( $(cat $BATINFO/charge_now)*100/$(cat $BATINFO/charge_full) )) ($(cat $BATINFO/status))" 26 27 CLKTEXT="time" 28 CLKSTAT=$(date +"%T %Y-%b-%d") 29 30 ## 31 ## Print formatting 32 ## 33 34 #print order 35 #default order is volume, RAM, battery, time 36 PRTORDER="vrbt" 37 38 DELIM="|" 39 40 #change order according to user input 41 if [ "$1" != "" ] 42 then 43 PRTORDER=$1 44 fi 45 46 #return string 47 PRTSTRING="" 48 49 #keep track of original order 50 ORGORDER=$PRTORDER 51 52 while [ "$PRTORDER" != "" ] 53 do 54 #get the first character 55 CRTOBJ=$(echo $PRTORDER | cut -b 1) 56 CRTSTRING="" 57 case $CRTOBJ in 58 "v") CRTSTRING="$VOLTEXT: $VOLSTAT" ;; 59 "t") CRTSTRING="$CLKTEXT: $CLKSTAT" ;; 60 "b") CRTSTRING="$BATTEXT: $BATSTAT" ;; 61 "r") CRTSTRING="$MEMTEXT: $MEMSTAT" ;; 62 *) 63 echo "bad!" 64 exit 1 65 ;; 66 esac 67 68 #on first run, don't print the delimiter 69 if [ "$PRTORDER" = "$ORGORDER" ] 70 then 71 PRTSTRING="$CRTSTRING" 72 else 73 PRTSTRING="$PRTSTRING $DELIM $CRTSTRING" 74 fi 75 76 #remove the first character 77 PRTORDER=$(echo $PRTORDER | sed "s/^.//g") 78 done 79 80 echo $PRTSTRING