Dropbox percentage used (en)

From Conky PitStop

Jump to: navigation, search

Dropbox Percentage Used

 Language   English   Français   


Scripts, bash and LUA, to display your DropBox statistics, also some single line commands to do the same. Thanks to wlourf and mobilediesel for these.

Don't forget to make the script executable.

Bash script: dropbox.sh

#!/bin/bash
# dropbox.sh

dbox=2.5 #size of your dropbox account
size=$(du -c $HOME/Dropbox | awk -v dbox=$dbox '/total/ {print 100*$1/1048576/dbox}')
echo ${size%.*}

For drawing a bar :

${execibar 60 $HOME/.conky/dropbox.sh}

See Note at the bottom of the page for "sizing" the execibar that has no sizing paramaters.

Samples:
DropBox2.png

Bash script: dropbox2.sh

NOTE: the use of %.2f to give 2 decimal places, a changeable variable.

#!/bin/bash
# dropbox2.sh
# by: wlourf & mobilediesel

dbox=3.0 ### size of your dropbox account
size=$(du -c /media/5/Dropbox | awk -v dbox=$dbox '/total/ {print 100*$1/1048576/dbox}')
echo ${size%.*}
echo 
## NOTE: BEGIN{Size=3.0} in two lines below
du -c /PATH_TO/Dropbox | awk  'BEGIN{Size=3.0} /total/ {Used=$1/1048576;printf "Size: %.2f GB",Size;printf " Used: %.2f GB",Used;printf " Free: %.2f GB\n",Size-Used}'

du -c /PATH_TO/Dropbox | awk  'BEGIN{Size=3.0} /total/{Used=$1/10485.76/Size;printf "Size: %.2f GB",Size;printf " Used: %.2f%",Used;printf " Free: %.2f%\n",100-Used}'

Bash script: dropbox3.sh

This one uses sqlite3

#!/bin/bash
# mobilediesel
Size=${1-2} #size of your dropbox account
Dropbox=$(sqlite3 $HOME/.dropbox/config.db "select * from config where key like '%path%'" | sed -e "/dropbox_path|/ s/dropbox\_path|//")
Used=$(du -c $Dropbox)
Perc=$(awk -v Size=$Size '/total/ {Used=100*$1/1048576/Size;printf "%.1f",Used;printf " %.1f",100-Used}' <<<"$Used")
Space=$(awk -v Size=$Size '/total/ {Used=$1/1048576;printf "%.1f",Used;printf " %.1f",Size-Used}' <<<"$Used")
echo "Size: ${Size}
Used: ${Space% *}GB (${Perc% *}%)
Free: ${Space#* }GB (${Perc#* }%)"

dropbox2.sh and dropbox3.sh in action:

Dropbox1-2.png

DropBox with single command lines in Conky

Directly in a conky (with 2.5, the size of the Dropbox account), for drawing a bar :

${execibar 60 du -c ~/Dropbox | awk  '/total/ {print $1/10485.76/2.5}' }

NOTES: Output can be rounded with "%.2f"', where 2 is the number of decimal to display. BEGIN{Size=2.5} The size of your DropBox

Here is an example for rounded output without decimals :

${execi 60 du -c ~/Dropbox | awk  '/total/ {printf"%.0f",$1/10485.76/2.5}' }

Some variations :

${execi 60 du -c ~/Dropbox | awk  'BEGIN{Size=2.5} /total/ {Used=$1/1048576;printf"Size: %.1f GB",Size;printf " Used: %.1f GB",Used;printf " Free: %.1fGB\n",Size-Used}'}

Output : Size: 2.5 GB Used: 0.2 GB Free: 2.3GB

${execi 60 du -c ~/Dropbox | awk  'BEGIN{Size=2.5} /total/{Used=$1/10485.76/Size;printf "Size: %.1f GB",Size;printf " Used:%.0f%",Used;printf " Free: %.0f%\n",100-Used}'}

Output : Size: 2.5 GB Used:7% Free: 93%

In Lua: dropbox.lua

--[[dropbox.lua
By: wlourf
call similar to this
lua_load /PATH/TO/dropbox.lua
]]
function conky_dropbox_pc(dbox,refresh)
    if conky_parse("$updates")%refresh == 0 then
        local f = io.popen("du -c $HOME/Dropbox | grep total | awk '{print $1}'"  )
        local size = f:read("*l")
        f:close()
        value = math.floor(100*size/1048576/dbox)
    end
    return value
end

and below TEXT:

${lua_bar dropbox_pc 2.5 5}


Note : execibar has no way to size it but you can size all bars with :

default_bar_size 90 20
TEXT
Personal tools
Namespaces
Variants
Actions
Navigation
English
Français
Toolbox