A cheeky little `ps_mem` query please

If i’ve picked the wrong category i apologise, but it’s certainly not an explicitly AL-based query so this seemed possibly a least-worst option.

My tower’s primary boot continues very happily to be Arch [via archfi] KDE. About a week ago after some prior mulling, i decided to change tower’s secondary boot from SolydK to SparkyLinux Xfce. It’s gone well & i’m pretty delighted with the result; SL is an impressive distro for those wishing a nice Debian 10 Testing system with some hand-holding. Oh gasp, i’ve gone OT in the OT!

For the past few days i have been mopping up odds & sods consequent from the changed distro. One of those tasks was customising my desktop Conkies to their new environment. One of my Conkies includes a command utilising ps_mem to print to desktop the “Top 10” total-ram-per-pgm output:

${voffset 0}${font Ubuntu Mono:size=10}${color 00ff00}${execpi 2 sudo ps_mem | tail -n13 | head -n10 | tac | awk -F '[' '{print $1}' | awk '{printf "%-25s %8s\n" , $9 $10 $11 , $7 $8}'}

This works nicely in all my Archies, once i facilitate it in sudoers. I never could get it to work in SolydK, & so far [admittedly with much less time spent atm than previously expended in SolydK] it’s also not a goer in Sparky [i presume Debian has some important system nuance different to the Archies which as yet i’ve failed to grasp]. The following might be only temporary, or instead this dirty kludge might become my long-term workaround, heehee [coz i’m a lazy cow]. UPDATE - OMG, i solved it; now it works!

SUPERSEDED!

My cumbersome workaround is to run this composite command in a terminal, which generates [after my initial entering of my sudo password] each 30 seconds the equivalent “Top 10” total-ram-per-pgm output that the more elegant Conky method does in all my Archies:

$> while true; do uptime; sudo python /home/guigirl/git/ps_mem/ps_mem.py | tail -n13 | head -n10 | tac | awk -F '[' '{print $1}' | awk '{printf "%-25s %8s\n" , $9 $10 $11 , $7 $8}'; sleep 30; done

 18:34:26 up  6:10,  1 user,  load average: 0.38, 0.43, 0.53
vivaldi-bin(74)             3.3GiB
thunderbird-bin           507.7MiB
cairo-dock                 89.2MiB
Xorg                       65.5MiB
radiostation               60.4MiB
xfdesktop                  48.9MiB
ksnip                      43.1MiB
mpd(2)                     41.8MiB
compiz                     37.0MiB
cantata                    37.0MiB

For that to work first i installed Python then ps_mem this indirect way: https://forums.bunsenlabs.org/viewtopic.php?pid=63733#p63733

As plainly seen in the link, the wise advice came from someone who might not be totally unfamiliar around this forum too, heehee.

The part of that post that intrigued me though in particular, & for which now i have finally got to the point [sorry], is this:

note that no superuser privileges are needed for my method

Unfortunately that’s not how it’s worked out for me. I still cannot run it without having to enter my sudo password.

guigirl@sparkylinuxtower[~/bin] 18:22:47 Mon Dec 28 $> ls -l
total 28
-rwxr-xr-x 1 guigirl guigirl   585 Dec 26 03:49 MyConky.sh
-rwxr-xr-x 1 guigirl guigirl 23828 Dec 25 18:32 ps-mem

guigirl@sparkylinuxtower[~/bin] 18:22:59 Mon Dec 28 $> sudo ps-mem
[sudo] password for guigirl: 
sudo: a password is required
guigirl@sparkylinuxtower[~/bin] 18:24:00 Mon Dec 28 $> 

Indeed, i can’t run it even with the password:

guigirl@sparkylinuxtower[~/bin] 18:24:00 Mon Dec 28 $> sudo ps-mem
[sudo] password for guigirl: 
sudo: ps-mem: command not found
guigirl@sparkylinuxtower[~/bin] 18:28:21 Mon Dec 28 $> 

Thus, for now, my workaround’s workaround is to give up on the Conky integration & merely run its Python version in a terminal from its spawning/parent directory as i showed higher up in the bigger codebox.

I have no doubt that the root cause is some error or oversight i’ve made, but atm i’m not seeing the forest for the trees, so hoped that your fresh perspective might spot my stuff-up pls?



Here’s my custom sudoers.d mod:

guigirl@sparkylinuxtower[~] 15:11:46 Mon Dec 28 $> sudo EDITOR=nano visudo -f /etc/sudoers.d/x-ps_mem

guigirl sparkylinuxtower = (root) NOPASSWD: /sbin/ps_mem
guigirl sparkylinuxtower = (root) NOPASSWD: /usr/bin/ps_mem
guigirl sparkylinuxtower = (root) NOPASSWD: /home/guigirl/git/ps_mem/ps_mem.py
guigirl sparkylinuxtower = (root) NOPASSWD: /home/guigirl/bin/ps-mem

Lines 1 - 3 didn’t work [1 & 2 were legacy/variations from my successful Archies method]. Line 4 did not exist when i began drafting this post, & it was specifically the rigour of needing to go over my scratch-notes & arrange my thoughts in preparing the post that triggered my realisation that i had forgotten to add line 4 specifically for my Sparky. The instant i wrote this file with that new line, my Conky came alive. Phew.

So, whilst my objective when i decided to start this post has now changed [coz my Sparky Conky IS now working with ps_mem after all], i’ve chosen to still complete & post it, for this question which i still don’t understand [note: this is simply a repeat from my hidden section marked “Superseded”, as i wouldn’t expect any normal humans to now bother with that section, only masochists like me :crazy_face:].

The part of that linked post that intrigued me is this:

note that no superuser privileges are needed for my method

Unfortunately that’s not how it’s worked out for me. I still cannot run it without having to enter my sudo password… or rather, atm my only way to not need the password is to have to first make that special sudoers.d mod.

Can anyone identify pls why/how one can achieve that objective of “no superuser privileges are needed for my methodwithout needing the sudoers.d mod?

Fwiw:

The result; picture

I just meant that no superuser privileges are needed to install ps_mem. You still need root to run the actual script.

1 Like

Oh, ah… whoops then. I read too much into it. Ta for your help.