Jump to content

Conky!


Recommended Posts

OK .. first.. lets show you WHY you might want to do this :)

 

post-798-1139953495.png

This is my conky :D You can see that this is weighted towards gentoo users

 

Ok, first the preparation. I will assume that you have conky installed (yum install conky, emerge conky, most systems have it now).

 

Ok so we need to create a couple of scripts to help create the output. If you aren't a gentoo user, skip these.

 

If you don't have a local user bin folder then you should make it:

mkdir ~/bin

 

~/bin/emerge-current.sh

#!/bin/bash
# emerge-current.sh by Hellf[i]re
#
# This script is designed to read the name of the last package compiled.
#
# As this script does read the entirety of emerge.log, it will be rather
# heavy on the CPU.  It shouldn't be enough to be noticable on newer (2.0Ghz+)
# processors, but it still should not be run more often than every 30 seconds.
#
# Usage:
# .conkyrc:	 ${execi [time] /path/to/script/emerge-current.sh}
#
# Usage Example
#			   ${execi 30 /home/youruser/scripts/emerge-current.sh}

tail -n 50 /var/log/emerge.log |\
tac |\
grep 'Compiling' |\
head |\
sed -e 's/.*(//' |\
sed -e 's/::.*)//' |\
head -n 1 |\
cut -d \) -f 1

 

~/bin/emerge-progress.sh

#!/bin/bash
# source: Jeremy_Z @ forums.gentoo.org http://forums.gentoo.org/viewtopic-t-351806-postdays-0-pos
torder-asc-start-550.html
#
# This script will report the progress of the last emerge command run.  It 
# reports the TOTAL percentage complete - not the percentage of the current
# package.  For example, if there are 110 packages currently being emerged, and
# it is on the 55th package, it will report 50.
#
# Usage:
# .conkyrc:	 ${execibar [time] /path/to/script/emerge-progress.sh}
#
# Usage Example
#			   ${execibar 30 /home/youruser/scripts/emerge-progress.sh}

tail -n 50 /var/log/emerge.log |\
tac |\
grep -v "Starting retry" |\
grep -iE '([0-9]* of [0-9]*)' -o -m 1 |\
sed -e 's/\(.*\) of \(.*\)/\1 \2/' |\
awk '{print 100.0*$1/$2}'

 

~/bin/emerge-status.sh

#!/bin/bash
#
# emerge-status.sh by Hellf[i]re
#
# This script will report the current status of portage.
#
# Usage:
# .conkyrc:	 ${execi [time] /path/to/script/emerge-current.sh}
#
# Usage Example
#			   ${execi 30 /home/youruser/scripts/emerge-current.sh}
#
# Known Bugs:
#  1) If there are two emerges running at once, when the first one finishes 
#	 running, the script will report the current status as "Completed".
#  2) If there is a emerge running and you run a search, the script will
#	 report the current status as "Completed", until the running emerge
#	 moves to the next package, or itself completes.
#  The reasons for this are twofold - one, it's a feature;) and two, there
#  would be far too much parsing required to find out the current status of
#  every command which is run in parallel.

STATUS=`tail -n 15 /var/log/emerge.log |\
grep -iE "Compiling|Cleaning|AUTOCLEAN|completed|search|terminating|rsync" |\
cut -d ' ' -f "2-" |\
grep -Ev 'Finished\.|Cleaning up\.\.\.' |\
tail -n 1`

#echo "$STATUS"

if [ "`echo "$STATUS" | grep -i compiling`" != "" ]; then echo Compiling
elif [ "`echo "$STATUS" | grep -i cleaning`" != "" ]; then echo Cleaning
elif [ "`echo "$STATUS" | grep -i autoclean`" != "" ]; then echo Autoclean
elif [ "`echo "$STATUS" | grep -i sync`" != "" ]; then echo Syncing
elif [ "`echo "$STATUS" | grep -i search`" != "" ]; then echo Searching
elif [ "`echo "$STATUS" | grep -i completed`" != "" ]; then echo Completed
elif [ "`echo "$STATUS" | grep -i terminating`" != "" ]; then echo Completed
fi

 

~/bin/lastsync.pl

#!/usr/bin/perl
use Date::Manip;

$date = `grep "Sync completed" /var/log/emerge.log | tail -n1 | cut -c-10`;
$date = &DateCalc("Jan 1, 1970  00:00:00 GMT",$date);
$date = UnixDate("$date","%A %H:%M");
print "$date";

 

Right thats those out of the way. Major thanks to the respective authors!

 

Now onto the ~/.conkyrc:

# ~/.conkyrc

background yes
use_xft no
on_bottom yes
font 6x10
update_interval 5.0
total_run_times 0
own_window no
own_window_transparent yes
double_buffer yes
minimum_size 180 5
draw_shades yes
draw_outline no
draw_borders no
stippled_borders 8
border_margin 4
border_width 1
default_color white
default_shade_color black
default_outline_color black
alignment top_right
gap_x 12
gap_y 12
no_buffers yes
uppercase no
cpu_avg_samples 2
net_avg_samples 2
override_utf8_locale no
use_spacer no


TEXT
${color #98c2c7}$nodename   linux-$kernel${alignr}${time %T}$color

${color #98c2c7}SYSTEM$color
 ${color #ffcb48}UPTIME$color $uptime${alignr}${color #ffcb48}LOAD$color $loadavg
 ${color #ffcb48}CPU$color	$cpu%${alignr}${color #ffcb48}FREQ$color $freq_dyn_g / $freq_g
${color #000000}${cpugraph cpu0 32,255 104e8b 0077ff}
 ${color #ffcb48}RAM$color	$mem / $memmax ${color #7f8ed3}${membar}$color
 ${color #ffcb48}SWAP$color  $swap / $swapmax ${color #7f8ed3}${swapbar}$color

${color #98c2c7}NETWORK$color
 ${color #ffcb48}PING$color  mute${execi 50 sh -c "ping -q -c5 mute | tail -n 2 | head -n 1 | cut -d',' -f3" }
 ${color #ffcb48}DOWN$color  ${downspeed eth0} k/s ${offset 80}${color #ffcb48}UP$color ${upspeed eth0} k/s
${color #000000}${downspeedgraph eth0 32,125 104e8b 0077ff} ${color #000000}${upspeedgraph eth0 32,125 104e8b 0077ff}

${color #98c2c7}STORAGE$color
 root ${fs_used /} / ${fs_size /} ${color #7f8ed3}${fs_bar /}$color

${color #98c2c7}PROCESSES$color
${color #ffcb48}NAME			 PID	 CPU%   MEM%$color
${color #007700}${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}$color
${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}
${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}
					   ${color #ffcb48}PROC$color  $processes${alignr}${color #ffcb48}RUN$color $running_processes
 ${color #ffcb48}MEM USAGE$color
${color #007700}${top_mem name 1} ${top_mem pid 1} ${top_mem cpu 1} ${top_mem mem 1}$color
${top_mem name 2} ${top_mem pid 2} ${top_mem cpu 2} ${top_mem mem 2}
${top_mem name 3} ${top_mem pid 3} ${top_mem cpu 3} ${top_mem mem 3}

${color #98c2c7}PORTAGE$color
 ${color #ffcb48}LAST SYNC$color ${execi 300 /home/znx/bin/lastsync.pl}
 ${color #ffcb48}LAST 3$color
${execi 50 genlop -lnu | sed -e 's/.*\([><]\+\)/	\1/' | tail -n 3 | tac}
 ${color #ffcb48}CURRENT$color
> ${color #98c2c7}${execibar 30 /home/znx/bin/emerge-progress.sh}$color
> ${execi 30 /home/znx/bin/emerge-current.sh}
> ${execi 30 /home/znx/bin/emerge-status.sh}

 

NOTE if you are not using gentoo remove the lines at the end of the ~/.conkyrc from PORTAGE down to the end. And if you ARE then switch the "/home/znx/bin" for your user. ^_^

 

Thats it.. start up conky and it will run. If you are using KDE/Gnome you will need to tamper with them to make it work because conky doesn't work well with them yet.

 

Conky's Home where I sourced the script and 99% of the idea to the production of this layout.

 

Weeeeee.. just a quick jaunt.. ask questions if you have any

 

OH ..

${color #ffcb48}PING$color  mute${execi 50 sh -c "ping -q -c5 mute | tail -n 2 | head -n 1 | cut -d',' -f3" }

 

This line is used to ping another system in my local network, you can either edit the name "mute" to be another machine, or remove the line as it will loose 100% of its packets.

 

See below for information about securing the genlop command.

 

Updated to fix mistakes found by dragon_788, many thanks!

Link to post
Share on other sites
  • 5 months later...

Ok so I decided to try out this portage thing with conky...

gentoostatus seems broken ...

 

./gentoo-status.sh: line 38: syntax error: unexpected end of file

 

if you can help that would be great heres a pic so far...

post-204-1153139591.png

Link to post
Share on other sites
./gentoo-status.sh: line 38: syntax error: unexpected end of file

 

Nice pic! Hrmm .. well that complaint is about the final line of the script, all I can suggest is that something is missing in that "if / fi" statement. Maybe try recopying that script.. works ok here still!

Link to post
Share on other sites

Yeah it was that and i hade to emerge genlop for it to work as well, still a problem with the status though doesn't output anything to conky... if i run it manually it says Completed being that the package is emerged and installed i'm lost on that one

 

Oh yeah znx somthing else i was wondering is it possible to run 2 different conky scripts at once?

 

Update:

 

Notice the Current status doesn't show anything

post-204-1154279356.png

Link to post
Share on other sites
still a problem with the status though doesn't output anything to conky... if i run it manually it says Completed being that the package is emerged and installed i'm lost on that one

 

Ah .. maybe its permissions.. is your user in the portage group?

 

Oh yeah znx somthing else i was wondering is it possible to run 2 different conky scripts at once?

 

well .. yes it is...

 

# conky -c firstconfigfile
# conky -c secondconfigfile

 

:)

Link to post
Share on other sites
  • 2 months later...
Any reason you couldn't use tail in your emerge status script rather than parsing the whole file? Might make it a bit easier on the resources so this could be used on lower end machines. I definitely plan on trying this once I get my machine up and happy.

 

The "status" one uses tail .. however you are absolutely correct, the gentoo-current one doesn't, I have amended it to fix it. Many thanks!

Link to post
Share on other sites
  • 2 weeks later...

Noticed a couple more issues now that I'm attempting to actually implement this, you call your file gentoo-progress in the topic but in the comments of the file its called emerge-progress and apparently in the code it is as well since I got an error until I changed the name. Actually ran into that issue on another file, all of them prefer to be called emerge-* rather than gentoo-*. Like enigma I had to emerge genlop in order for the script to be entirely happy as well. Also, in order for the script to work you DO have to be a member of the portage group, otherwise genlop complains about permissions to the emerge.log. I was wondering if it was possible to somehow have genlop run as the portage user rather than the logged in user as having your user in the portage group (apparently) presents a security risk since someone could emerge/unmerge packages harmful to your system, I don't care much since mine is a personal system with password protection, but perhaps others are using their work machines with this. Other than that its working well and now that I've tweaked it to run its very sweet, now I just hafta fix the alignment and I'll be in heaven. Samurize for Windows, meet Conky for Linux, your very worthy rival.

Link to post
Share on other sites
...emerge-* rather than gentoo-*...

 

Doh! Yeah thanks I've fixed that!

 

Also, in order for the script to work you DO have to be a member of the portage group

 

Yup and I agree it is a security risk on a multiuser system. You ask a way around it, the answer to that would be sudo.

 

Sudo is very capable at providing access to a single command for a single purpose. So you will need to install sudo first (gentoo is missing sudo by default).

 

# emerge app-admin/sudo

 

Then for your sudoers file (edited with visudo) do:

User_Alias  GENLOP = znx, dragon, enigma
GENLOP   ALL=(%portage) NOPASSWD: /usr/bin/genlop -lnu

 

Now with that in there, you can do this as any of the listed GENLOP users:

$ sudo -u portage /usr/bin/genlop -lnu

 

Bing, works! So now it can act in the script. The good thing about this is that I particularly restricted the command to a set option, this in effect ensures that its only that command that the user runs. I should point out that whilst sudo is more secure than having a group but its still not perfect and never treat it as :)

 

Ok, so MANY thanks dragon, you debugged my howto! yay

Link to post
Share on other sites
:lol: And I have to say once again thanks to you znx, your howto is awesome and giving an example of a solid use for sudo (rather than always opening a terminal and su'ing almost immediately) is a greta kick in the pants to set up and configure sudo which was on my todo list but never made it to the top. The Conky config you've provided is a nifty addition to the Beryl/XGL environment I have going and if I can get the kinks worked out it'll make my transition from Windows to Linux as my desktop OS a lot more rewarding right off the bat.
Link to post
Share on other sites
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...