LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Find - battery life, CPU Usage,Wireless Signal Level , Congestion Level (http://www.linuxquestions.org/questions/programming-9/find-battery-life-cpu-usage-wireless-signal-level-congestion-level-631256/)

md_imranullah 03-28-2008 10:46 AM

Find - battery life, CPU Usage,Wireless Signal Level , Congestion Level
 
hi,
I need a script in any language php or perl or even basic unix shell script to find the cpu usage battery life congestion level and the wireless signal level.

i have one for battery i want for others

print read %/proc/acpi/battery/C138/state

There are many widgets available for that. but i just need one using scripting language so that i can use it in my project.

Imranullah Mohammed

unSpawn 03-28-2008 06:58 PM

If all your tinkering amounts to just "print read something" then I really suggest you solve this yourself.
It's your project so facing the challenge makes you learn the most.

Mr_C 05-20-2008 09:45 PM

I'm looking for something like this as well. What I came up with didn't work as I expected it to.

In my .bashrc

Code:

battery() {
        capacity=`awk '/last full capacity:/ { print $4 }' /proc/acpi/battery/BAT0/info`
        remaining=`awk '/remaining capacity:/ { print $3 }' /proc/acpi/battery/BAT0/state`
        charging=`awk '/charging state:/ { print $3 }' /proc/acpi/battery/BAT0/state`
        echo "BAT: $((remaining*100/capacity))%";
}

PS1="\[\033[0;32m\]\u\[\033[0;31m\]|\[\033[0;32m\]\h \[\033[0;31m\]| BAT:`battery` \[\033[0;31m\]|\[\033[0;32m\] \[\033[0;37m\]\w\[\033[1;30m\]




And in my .zshrc

Code:

source ~/.aliases

function precmd {

    local TERMWIDTH
    (( TERMWIDTH = ${COLUMNS} - 1 ))

    ###
    # Truncate the path if it's too long.
   
    PR_FILLBAR=""
    PR_PWDLEN=""
   
    local promptsize=${#${(%):---(%n@%m:%l)---()--}}
    local pwdsize=${#${(%):-%~}}
   
    if [[ "$promptsize + $pwdsize" -gt $TERMWIDTH ]]; then
            ((PR_PWDLEN=$TERMWIDTH - $promptsize))
    else
        PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize)))..${PR_HBAR}.)}"
    fi
}


setopt extended_glob
preexec () {
    if [[ "$TERM" == "screen" ]]; then
        local CMD=${1[(wr)^(*=*|sudo|-*)]}
        echo -n "\ek$CMD\e\\"
    fi
}

###
# Checks battery state
# This resides on acpi

capacity=`awk '/last full capacity:/ { print $4 }' /proc/acpi/battery/BAT0/info`
remaining=`awk '/remaining capacity:/ { print $3 }' /proc/acpi/battery/BAT0/state`
charging=`awk '/charging state:/ { print $3 }' /proc/acpi/battery/BAT0/state`
BAT_PER="BAT $((remaining*100/capacity))"


setprompt () {
    ###
    # Need this so the prompt will work.

    setopt prompt_subst


    ###
    # See if we can use colors.

    autoload colors zsh/terminfo
    if [[ "$terminfo[colors]" -ge 8 ]]; then
        colors
    fi
    for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
        eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
        eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
        (( count = $count + 1 ))
    done
    PR_NO_COLOUR="%{$terminfo[sgr0]%}"


    ###
    # See if we can use extended characters to look nicer.
   
    typeset -A altchar
    set -A altchar ${(s..)terminfo[acsc]}
    PR_SET_CHARSET="%{$terminfo[enacs]%}"
    PR_SHIFT_IN="%{$terminfo[smacs]%}"
    PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
    PR_HBAR=${altchar[q]:--}
    PR_ULCORNER=${altchar[l]:--}
    PR_LLCORNER=${altchar[m]:--}
    PR_LRCORNER=${altchar[j]:--}
    PR_URCORNER=${altchar[k]:--}

   
    ###
    # Decide if we need to set titlebar text.
   
    case $TERM in
        xterm*)
            PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
            ;;
        screen)
            PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
            ;;
        *)
            PR_TITLEBAR=''
            ;;
    esac
   
   
    ###
    # Decide whether to set a screen title
    if [[ "$TERM" == "screen" ]]; then
        PR_STITLE=$'%{\ekzsh\e\\%}'
    else
        PR_STITLE=''
    fi
   
   
   
    ###
    # Finally, the prompt.

    PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
$PR_CYAN$PR_SHIFT_IN$PR_ULCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
$PR_GREEN%(!.%SROOT%s.%n)$PR_WHITE@$PR_GREEN%m$PR_WHITE:$PR_GREEN%l\
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_HBAR${(e)PR_FILLBAR}$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
$PR_MAGENTA%$PR_PWDLEN<...<%~%<<\
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_URCORNER$PR_SHIFT_OUT\

$PR_CYAN$PR_SHIFT_IN$PR_LLCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
%(?..$PR_LIGHT_RED%?$PR_BLUE:)\
$PR_LIGHT_BLUE%(!.$PR_RED.$PR_WHITE)%#$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_NO_COLOUR '

    RPROMPT=' $PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_BLUE$PR_HBAR$PR_SHIFT_OUT\
($PR_YELLOW%D{%H:%M}$PR_BLUE)$PR_SHIFT_IN$PR_HBAR\
($PR_RED$BAT_PER$PR_BLUE)$PR_SHIFT_IN$PR_HBAR\
$PR_CYAN$PR_LRCORNER$PR_SHIFT_OUT$PR_NO_COLOUR'

    PS2='$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_BLUE$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT(\
$PR_LIGHT_GREEN%_$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT$PR_NO_COLOUR '
}

setprompt


Right now I'm unhappy with either: I want when I press enter the PS2 prompt to update the current state but that doesn't happen; it keeps the last calcuated value. Even though its calculating correctly. The time is update but not that calculation

If for example in the .bashrc I type 'battery' it prints accordingly but I want it being displayed in teh PS2 header...


All times are GMT -5. The time now is 09:17 AM.