1

Conky is a system monitor software. I want to display the directory size of /usr and /var. Unfortunately I did not found any conky command so i made my own.

/usr $alignr${exec du -sch /usr | head -n1 | awk '{print $1}'}
/var $alignr${exec du -sch /var | head -n1 | awk '{print $1}'}

It works as expected for my /usr directory. The same command for the /var directory messes up my syslog:

#cat /var/log/syslog | tail -n 8
Oct 27 15:17:31 Hans gnome-session[1155]: du: das Verzeichnis „/tmp/systemd-private-3f1797004e2e4fceacc1baad91af9e67-cups.service-LhZ0Wi“ kann nicht gelesen werden: Keine Berechtigung
Oct 27 15:17:31 Hans gnome-session[1155]: du: das Verzeichnis „/tmp/pulse-PKdhtXMmr18n“ kann nicht gelesen werden: Keine Berechtigung
Oct 27 15:17:32 Hans gnome-session[1155]: du: das Verzeichnis „/tmp/.xrdp/xrdp-sesman-yqTUiU“ kann nicht gelesen werden: Keine Berechtigung
Oct 27 15:17:32 Hans gnome-session[1155]: du: das Verzeichnis „/tmp/.xrdp/xrdp-5M2L0E“ kann nicht gelesen werden: Keine Berechtigung
Oct 27 15:17:32 Hans gnome-session[1155]: du: das Verzeichnis „/tmp/systemd-private-3f1797004e2e4fceacc1baad91af9e67-colord.service-3EtIBW“ kann nicht gelesen werden: Keine Berechtigung
Oct 27 15:17:32 Hans gnome-session[1155]: du: das Verzeichnis „/tmp/systemd-private-3f1797004e2e4fceacc1baad91af9e67-rtkit-daemon.service-TgoTcd“ kann nicht gelesen werden: Keine Berechtigung
Oct 27 15:17:32 Hans gnome-session[1155]: du: das Verzeichnis „/tmp/systemd-private-3f1797004e2e4fceacc1baad91af9e67-cups.service-LhZ0Wi“ kann nicht gelesen werden: Keine Berechtigung
Oct 27 15:17:32 Hans gnome-session[1155]: du: das Verzeichnis „/tmp/pulse-PKdhtXMmr18n“ kann nicht gelesen werden: Keine Berechtigung

The Problem is that I need superuser rights to execude the du command. Is there another way to get the directory size of the /var directory without permission problems for no-root-users?

Debian 8.2(jessie) | Linux 3.16.0 | GNOME Shell 3.14.4 | Conky 1.9.0

  • 3
    du is a fairly expensive operation. You shouldnt be running it every few seconds with conky. – meuh Oct 27 '15 at 14:44
  • You're better off using df for this effort than du. You won't need superuser permissions to run df since it (unlike du) doesn't need to stat() all the files and subdirectories within it's target (thus requiring permissions to read all those files, many of which shouldn't be read by normal users). – John Oct 27 '15 at 14:47
  • @John I was thinking the same, would just like to add that for this to work, mount /var on it's own fs, as df reports fs, not dir – Dani_l Oct 27 '15 at 14:53
  • possibly best - create lvm volume for /var and df that. – Dani_l Oct 27 '15 at 14:54
  • I (almost) always create a separate filesystem for /var anyway, so I'd assumed it was already it's own filesystem. IMO, you're asking for trouble if it's not it's own filesystem. – John Oct 27 '15 at 14:55
1

Yes, you can give your user the right to run sudo du /var with no password, I'll show you how later. However, do you really want this? There are very few files and subdirectories that du needs root access to. The difference is reported size between sudo du /var and du /var is tiny (at least on my system):

$ sudo du -s /var/
1830596 /var/
$  du -s /var/
1826040 /var/

Those both resolve to exactly the same number of gigabytes:

$ sudo du -hs /var
1.8G    /var
$ du -hs /var
1.8G /var

So, is such a small difference really worth it? It seems to me that a far simpler solution would be to just ignore the error messages by sending them to /dev/null:

/var $alignr${exec du -sh /var 2>/dev/null | awk '{print $1}'}

Note that I removed the head since that was only needed because you were using the -c option to print the total.

Since du is quite heavy and I doubt you really need this run every few seconds, you could also tell conky to only run the command once a minute:

/var $alignr${execi 60  du -sh /var 2>/dev/null | awk '{print $1}'}

If you feel that you really, really need the precise size of /var, run sudo visudo and add this line:

schmiddl ALL=NOPASSWD:/usr/bin/du -ch /var

Once you save the file, the user schmiddl will have the right to run sudo du -ch /var without a password, so you can add this to your .conokyrc:

/var $alignr${execi 60  sudo du -sh /var | awk '{print $1}'}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.