You are not logged in.
I'm trying to display my CPU usage and other things in the status bar (other things being HDD usage and the current song playing in MOC). The only one of which I know how to do is find the current song playing, but for some reason I can't get it working. I tried making it:
status() {
$(mocp -i | grep SongTitle) '|' echo -n $(uptime | sed 's/.*://; s/,//g') '|' $(date)
}
That doesn't work, but it's odd because if you place that at the end of that line it works.
Last edited by oib111 (2009-07-13 18:41:32)
Offline
Try moving echo -n to the start of the line.
status() {
echo -n $(mocp -i | grep SongTitle) '|' $(uptime | sed 's/.*://; s/,//g') '|' $(date)
}
Offline
Thank's that worked, but how do I display the CPU usage and HDD usage?
Offline
Not sure about cpu usage but for hd usage in Gb/Mb you could do
df -h | grep /dev/sda* | awk '{print $3}'
* partition you want to monitor
or substitute 3 for 5 if you want it displayed as a percentage.
Offline
Thanks! Maybe I can extract the CPU usage from top using grep ?
Offline
#!/bin/bash
PREV_TOTAL=0
PREV_IDLE=0
while true; do
CPU=(`cat /proc/stat | grep '^cpu '`) # Get the total CPU statistics.
unset CPU[0] # Discard the "cpu" prefix.
IDLE=${CPU[4]} # Get 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"
echo -en "[ Cpu :: $DIFF_USAGE% ]" | wmiir create /rbar/cpu
# Remember the total and idle CPU times for the next check.
PREV_TOTAL="$TOTAL"
PREV_IDLE="$IDLE"
# Wait before checking again.
sleep 1
done
Offline