LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-28-2008, 09:46 AM   #1
md_imranullah
LQ Newbie
 
Registered: Jan 2008
Posts: 6

Rep: Reputation: 0
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
 
Old 03-28-2008, 05:58 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,140
Blog Entries: 54

Rep: Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791
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.
 
Old 05-20-2008, 08:45 PM   #3
Mr_C
Member
 
Registered: Jan 2004
Location: Trinidad & Tobago
Distribution: Slackware
Posts: 317

Rep: Reputation: 30
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...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
emacs in run level 3 then switch to X (level 7) then back to level 3 dsoliver Slackware 3 09-01-2006 03:31 AM
Need a command/program to find out laptop battery level beserkjay Slackware 10 06-29-2006 06:39 PM
Wireless mouse battery level detection? daihard Linux - Hardware 2 09-27-2005 04:04 AM
Battery Level; Wireless jeopardyracing Linux - Laptop and Netbook 6 09-16-2004 12:08 PM
Battery monitor not showing battery level? morrolan Linux - Laptop and Netbook 4 03-18-2004 04:42 AM


All times are GMT -5. The time now is 09:11 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration