Reply
Thread Tools
peterleinchen's Avatar
Posts: 4,117 | Thanked: 8,901 times | Joined on Aug 2010 @ Ruhrgebiet, Germany
#11
What is the output of $getcurrent during execution?
I would also guess anon-numeric string?
Or what is the error message. Or full output of script.
__________________
SIM-Switcher, automated SIM switching with a Double (Dual) SIM adapter
--
Thank you all for voting me into the Community Council 2014-2016!

Please consider your membership / supporting Maemo e.V. and help to spread this by following/copying this link to your TMO signature:
[MC eV] Maemo Community eV membership application, http://talk.maemo.org/showthread.php?t=94257

editsignature, http://talk.maemo.org/profile.php?do=editsignature
 

The Following User Says Thank You to peterleinchen For This Useful Post:
Posts: 1,163 | Thanked: 1,873 times | Joined on Feb 2011 @ The Netherlands
#12
good point but AFAIK it doesn't support all the typical calculation shizzle However you could use the "dc" applet delivered with busybox

Code:
 dc --help
BusyBox v1.20.2 (Debian 1.20.2power4+thumb0) multi-call binary.

Usage: dc EXPRESSION...

Tiny RPN calculator. Operations:
+, add, -, sub, *, mul, /, div, %, mod, **, exp, and, or, not, eor,
p - print top of the stack (without popping),
f - print entire stack,
o - pop the value and set output radix (must be 10, 16, 8 or 2).
Examples: 'dc 2 2 add p' -> 4, 'dc 8 8 * 2 2 + / p' -> 16
__________________
N900 loaded with:
CSSU-T (Thumb)
720p recording,
Pierogi, Lanterne, Cooktimer, Frogatto
N9 16GB loaded with:
Kernel-Plus
--
[TCPdump & libpcap | ngrep]
--
donate
 
Posts: 2,290 | Thanked: 4,133 times | Joined on Apr 2010 @ UK
#13
Originally Posted by peterleinchen View Post
Or what is the error message. Or full output of script.
BASH
Code:
/media/mmc1 $ bash swapblocks.sh 
261896 ublocks
134090752 ubytes
130948 ukbytes, 127 umbytes, 0 ugbytes
838852608 totalswapbytes
1 lasttotalsb
134090751 getcurrent
13409075100 timeshundred
15 % Swap Fragmented
ASH
Code:
/media/mmc1 $ sh swapblocks.sh   
261896 ublocks
134090752 ubytes
130948 ukbytes, 127 umbytes, 0 ugbytes
838852608 totalswapbytes
1 lasttotalsb
134090751 getcurrent
524173212 timeshundred
0 % Swap Fragmented
__________________

Wiki Admin
sixwheeledbeast's wiki
Testing Squad Subscriber
- mcallerx - tenminutecore - FlopSwap - Qnotted - zzztop - Bander - Fight2048 -


Before posting or starting a thread please try this.
 
Posts: 2,290 | Thanked: 4,133 times | Joined on Apr 2010 @ UK
#14
Originally Posted by mr_pingu View Post
However you could use the "dc" applet delivered with busybox
Not an option, bbpower only function.

Code:
dc --help
-sh: dc: not found
__________________

Wiki Admin
sixwheeledbeast's wiki
Testing Squad Subscriber
- mcallerx - tenminutecore - FlopSwap - Qnotted - zzztop - Bander - Fight2048 -


Before posting or starting a thread please try this.
 
peterleinchen's Avatar
Posts: 4,117 | Thanked: 8,901 times | Joined on Aug 2010 @ Ruhrgebiet, Germany
#15
int32!

Do your calc not as byte, but as kB or MB (not that exact, but hey you also do not round the percentage )
__________________
SIM-Switcher, automated SIM switching with a Double (Dual) SIM adapter
--
Thank you all for voting me into the Community Council 2014-2016!

Please consider your membership / supporting Maemo e.V. and help to spread this by following/copying this link to your TMO signature:
[MC eV] Maemo Community eV membership application, http://talk.maemo.org/showthread.php?t=94257

editsignature, http://talk.maemo.org/profile.php?do=editsignature
 

The Following 4 Users Say Thank You to peterleinchen For This Useful Post:
Posts: 1,808 | Thanked: 4,272 times | Joined on Feb 2011 @ Germany
#16
Add.: @peterleinchen beat me!

Originally Posted by sixwheeledbeast View Post
BASH
Code:
/media/mmc1 $ bash swapblocks.sh 
261896 ublocks
134090752 ubytes
130948 ukbytes, 127 umbytes, 0 ugbytes
838852608 totalswapbytes
1 lasttotalsb
134090751 getcurrent
13409075100 timeshundred
15 % Swap Fragmented
ASH
Code:
/media/mmc1 $ sh swapblocks.sh   
261896 ublocks
134090752 ubytes
130948 ukbytes, 127 umbytes, 0 ugbytes
838852608 totalswapbytes
1 lasttotalsb
134090751 getcurrent
524173212 timeshundred
0 % Swap Fragmented
524173212 is ((134090751 * 100) mod 2*1024**3), meaning busybox does only 32-bit signed arithmetic.

Didn't look at the script, but I guess that whenever you read values that are expected to overflow a signed 32-bit number, you should do some kind of "renormalization" (e.g. divide by 1000, or by 1000000, as appropriate), and keep track of the "multiplier" in another variable. If you really need it, that is.

Don't know at the moment if dc or bc are included in busybox(-power), but AWK is always there, and does (or should do) the job correctly.
 

The Following 5 Users Say Thank You to reinob For This Useful Post:
Posts: 2,290 | Thanked: 4,133 times | Joined on Apr 2010 @ UK
#17
Thank you all. Makes sense now.
Here's the fixed script and output, for anybody interested.
Should be able to use in FlopSwap now.

Code:
#!/bin/sh

# Setup notification banner
banner(){
o=org
f=freedesktop
n=Notifications
run-standalone.sh dbus-send --type=method_call \
--dest=$o.$f.$n /$o/$f/$n $o.$f.$n.SystemNoteInfoprint string:"$1"
}

# Setup notification dialog
dialog(){
o=org
f=freedesktop
n=Notifications
run-standalone.sh dbus-send --type=method_call \
--dest=$o.$f.$n /$o/$f/$n $o.$f.$n.SystemNoteDialog string:"$1" uint32: string:
}

#Get current swap from /proc/swaps
disk=$(cat /proc/swaps | awk '/dev/ {print $1}' | cut -d "/" -f 3)
#Get blocks used since boot from /proc/diskstats
ublocks=$(awk '{if ($3=="'"$disk"'") print $10}' /proc/diskstats)
echo $ublocks ublocks
#Multiply blocks by 512 to get used bytes
ubytes=$(($ublocks*512))
#Calculate used bytes into Kb, Mb and Gb
echo $ubytes ubytes
ukbytes=$(($ubytes/1024))
umbytes=$(($ubytes/1024/1024))
ugbytes=$(($ubytes/1024/1024/1024))
echo $ukbytes ukbytes, $umbytes umbytes, $ugbytes ugbytes
#Get Swap size from /proc/swaps
swapsize=$(awk '{if ($1=="'"/dev/$disk"'") print $3}' /proc/swaps)
#Divide by 1024 to get swap size in megabytes
swapsizembytes=$(($swapsize/1024))
echo $swapsizembytes swapsizembytes
#Get last megabytes value from /tmp folder
lasttotalsmb=$(cat /tmp/flopswaplast | awk '{print $1}')
echo $lasttotalsmb lasttotalsmb
#Subtract last from current value to get latest used value
getcurrent=$(($umbytes-$lasttotalsmb))
echo $getcurrent getcurrent
timeshundred=$(($getcurrent*100))
echo $timeshundred timeshundred
#Get divide to get percent
getpercent=$(($timeshundred/$swapsizembytes))
echo $getpercent % Fresh Swap Written
#Print banner
banner "$getpercent % Fresh Swap Written
$getcurrent Mb of $swapsizembytes Mb"
#If 94% show warning dialog
if [ $getpercent -ge 94 ]; then
dialog "

***Fresh Swap Recommended***
Used \"$getcurrent Mb ($getpercent)\" of \"$swapsizembytes Mb\"
Device $(hostname) on $(date)

"
fi
Code:
/media/mmc1 $ sh swapblocks.sh 
262984 ublocks
134647808 ubytes
131492 ukbytes, 128 umbytes, 0 ugbytes
799 swapsizembytes
1 lasttotalsmb
127 getcurrent
12700 timeshundred
15 % Fresh Swap Written
__________________

Wiki Admin
sixwheeledbeast's wiki
Testing Squad Subscriber
- mcallerx - tenminutecore - FlopSwap - Qnotted - zzztop - Bander - Fight2048 -


Before posting or starting a thread please try this.

Last edited by sixwheeledbeast; 2012-12-05 at 21:55.
 

The Following User Says Thank You to sixwheeledbeast For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 17:54.