You are not logged in.
I would like conky to show all drives/partitions that are currently mounted.
Right now I use the following:
${if_mounted /}
/${goto 60}${fs_used /}${goto 120}\
${if_match ${fs_used_perc /}<10}\
${fs_used_perc /}%\
${else}${if_match ${fs_used_perc /}<70}\
${fs_used_perc /}%\
${else}${if_match ${fs_used_perc /}<100}\
$color9${fs_used_perc /}%$color\
${else}
${endif}${endif}${endif}\
${alignr}${fs_size /}${endif}\
${if_mounted /home}
/home${goto 60}${fs_used /home}${goto 120}\
${if_match ${fs_used_perc /home}<10}\
${fs_used_perc /home}%\
${else}${if_match ${fs_used_perc /home}<70}\
${fs_used_perc /home}%\
${else}${if_match ${fs_used_perc /home}<100}\
$color9${fs_used_perc /home}%$color\
${else}
${endif}${endif}${endif}\
${alignr}${fs_size /home}${endif}\
${if_mounted /media/ghorvath/KINGSTON}
KINGS${goto 60}${fs_used /media/ghorvath/KINGSTON}${goto 120}\
${if_match ${fs_used_perc /media/ghorvath/KINGSTON}<10}\
${fs_used_perc /media/ghorvath/KINGSTON}%\
${else}${if_match ${fs_used_perc /media/ghorvath/KINGSTON}<70}\
${fs_used_perc /media/ghorvath/KINGSTON}%\
${else}${if_match ${fs_used_perc /media/ghorvath/KINGSTON}<100}\
$color9${fs_used_perc /media/ghorvath/KINGSTON}%$color\
${else}
${endif}${endif}${endif}\
${alignr}${fs_size /media/ghorvath/KINGSTON}${endif}\
This does exactly what I would like to have as long as I list all the possible drives. This is of course not a problem with the fixed drives, but listing all usb sticks that I will ever stick into my laptop is clearly not an option. And also, adding extra several lines of code per drives is not particularly elegant, even if it does the job.
Does anyone know any way how to do this? Like how to make a loop within conky? I am thinking about something like this:
for DRIVES in AllDrives --somehow obtained by some bash script or something
${if_mounted /media/ghorvath/DRIVE}
DRIVE${goto 60}${fs_used /media/ghorvath/DRIVE}${goto 120}\
${if_match ${fs_used_perc /media/ghorvath/DRIVE}<10}\
${fs_used_perc /media/ghorvath/DRIVE}%\
${else}${if_match ${fs_used_perc /media/ghorvath/DRIVE}<70}\
${fs_used_perc /media/ghorvath/DRIVE}%\
${else}${if_match ${fs_used_perc /media/ghorvath/DRIVE}<100}\
$color9${fs_used_perc /media/ghorvath/DRIVE}%$color\
${else}
${endif}${endif}${endif}\
${alignr}${fs_size /media/ghorvath/DRIVE}${endif}\
endfor
Anybody has any cool ideas to do this?
Last edited by ghorvath (2018-06-27 06:59:01)
Offline
I think the if_existing variable is the one you want to use; something like -
${if_existing <mount point>}
Probably find an example in here - been a recurring question for conky.
You must unlearn what you have learned.
-- yoda
Online
I don't see how if_existing helps more here than if_mounted. I still need some way to loop over the /media/ghorvath folder.
I will take a look at the (incredibly long) topic you cited.
Offline
No idea about conky, but you could bash df something up and stick that into conky, for example
a ) returns a lot of stuff:
df -h --output # to see all there is, especially the type column
Filesystem Type Inodes IUsed IFree IUse% Size Used Avail Use% File Mounted on
udev devtmpfs 2.0M 596 2.0M 1% 7.9G 0 7.9G 0% - /dev
tmpfs tmpfs 2.0M 935 2.0M 1% 1.6G 18M 1.6G 2% - /run
/dev/sda4 ext4 6.3M 974K 5.4M 16% 99G 87G 7.1G 93% - /
tmpfs tmpfs 2.0M 12 2.0M 1% 7.9G 44M 7.8G 1% - /dev/shm
tmpfs tmpfs 2.0M 5 2.0M 1% 5.0M 4.0K 5.0M 1% - /run/lock
tmpfs tmpfs 2.0M 15 2.0M 1% 7.9G 0 7.9G 0% - /sys/fs/cgroup
/dev/sda1 vfat 0 0 0 - 197M 20M 178M 10% - /boot/efi
tmpfs tmpfs 2.0M 17 2.0M 1% 1.6G 4.0K 1.6G 1% - /run/user/1000
pi@192.168.1.6:/media/usb/filmi fuse.sshfs 117M 1.2K 117M 1% 1.8T 199G 1.6T 12% - /home/b/pi
/dev/sde1 ext4 59M 2.2K 59M 1% 916G 377G 494G 44% - /media/b/data
and b ) is a lot nicer:
df -h -t ext4 -t vfat -t fuse.sshfs | grep -v "boot" # some filtering
Filesystem Size Used Avail Use% Mounted on
/dev/sda4 99G 87G 7.1G 93% /
pi@192.168.1.6:/media/usb/filmi 1.8T 199G 1.6T 12% /home/b/pi
/dev/sde1 916G 377G 494G 44% /media/b/data
c ) could be
df -h -t ext4 -t vfat -t fuse.sshfs --output=target,pcent | grep -v "boot"
# Probably missing ntfs here ^
Mounted on Use%
/ 89%
/home/b/pi 12%
/media/b/data 44%
see: man df
From there is more bash and or conky to get your percentages into bars or whatever desired.
Last edited by brontosaurusrex (2018-06-24 21:13:44)
Offline
i like to create small bash scripts that produce conky syntax, and then call them with
${execp /path/to/script}
in your case, i would read /etc/mtab periodically, filter out unwanted stuff, build in the "${fs_used... " stuff and display that in conky.
Offline
Thank you both for the ideas! Both could work, I will see what I can come up with.
One last question: is there any easy way to do a loop in conky? (That would significantly make the solution easier to me.) Or would that only work with some Lua scripting?
Also, I wonder which of these possibilities is the most performance/battery efficient.
Thanks!
Offline
is there any easy way to do a loop in conky?
i don't understand what you mean.
conky runs in an infinite loop already.
Also, I wonder which of these possibilities is the most performance/battery efficient.
usually those that involve the least computing.
calling an external script from conky is not the most lightweight, that's why i chose dash instead of bash for this half solution:
#!/bin/dash
prefix="\${goto 80}"
suffix="\${voffset -2}"
df -h | grep '^/dev' | while read device discard discard discard percent mountpoint; do
echo "$prefix$device mounted on $mountpoint: $percent$suffix"
done
there's no colour coding here, but i'm sure you can figure it out.
Offline
ghorvath wrote:is there any easy way to do a loop in conky?
i don't understand what you mean.
conky runs in an infinite loop already.
I mean, can I do something like
for i=1 to 10
...
within the conky script?
Thanks for the dash code, I will modify it to my needs. It works very nicely.
You are saying that (among all shell scripts) dash is probably the most lightweight?
Thanks for all the help!
Offline
Still don't know about conky loops, but why not draw everything in terminal (so it is usable in cli as well)?
See the prototype of ascii bar funtion here. (It's me, I just don't ever feel writing anything specifically for conky).
Last edited by brontosaurusrex (2018-06-25 20:27:25)
Offline
Thanks! Using ohnonot's example, I quickly wrote the following which seems to do what I want:
#!/bin/dash
df -h | grep '^/dev' | while read DEVICE SIZE USED FREE PERCENT MOUNT
do
PERC=${PERCENT%?}
if [ $PERC -lt 10 ]
then
PERCENT=" $PERC%"
elif [ $PERC -lt 60 ]
then
PERCENT=" $PERC%"
elif [ $PERC -lt 100 ]
then
PERCENT=" \${color9}$PERC%\${color}"
else
PERCENT="$PERC%"
fi
echo "$MOUNT\${goto 60}$USED\${goto 120}$PERCENT\${alignr}$SIZE"
done
All is left to do is whenever there are at least two / signs in the name (meaning we are in /mnt/somewhere or /media/somewhere) then I only want whatever is after the last /, and at most 5 characters, because more would not fit conky.
Also, I am thinking about aligning the $USED to the right, needing some kind of check on the number of characters of $USED. Anyway, those are for another day.
Thanks, everyone for the help!
Offline
Glad that you got the needed, meantime in the evil layer, there is a term script, which may return:
time dfascii
free mount
|||||||||||||||||||| 16G /
|| 1.6T /home/b/pi
|||||||||| 491G /media/b/data
dfascii 0.01s user 0.00s system 56% cpu 0.014 total
and has nothing to do with conky specifically.
Last edited by brontosaurusrex (2018-06-27 19:50:09)
Offline
I only want whatever is after the last /
easy:
MOUNT="${MOUNT##*/}"
and at most 5 characters, because more would not fit conky.
that would be easy in bash, but would require use of an external command in dash (thus somewhat negating its lightweightness).
but i must say, even if you run a single core machine from 10 years ago, it is hardly a concern. well it depends on the update_interval; i have always used 3s; if you use much less than 1s it might show evtl.
anyhow, in bash:
MOUNT="${MOUNT: -5}"
in dash, you'd have to resort to something else.
Offline
Thanks for all the help, marked the thread solved.
Offline