You are not logged in.

#141 2020-09-16 18:08:51

sleekmason
zoom
Registered: 2018-05-22
Posts: 1,103
Website

Re: Handy command-line stuff for terminals or scripts

A nice option to using root in menus and keybinds in Debian.

Create a script in /usr/local/bin that calls pkexec with env set.

cd /usr/local/bin

create the file:

sudo nano gksudo

Then add this:

pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY $@

Hit F2 and save.
Then make executable:

sudo chmod 755 gksudo

Basically this creates a link to pkexec with the env variables already in place, so using:

gksudo pcmanfm /home/sleekmason

will now work in a menu entry or keybind to open pcmanfm as root in my home folder. Replace program as desired and/or add cool options.  I have a few keybinds set for commonly used folders in /etc.

Last edited by sleekmason (2020-09-16 19:07:11)

Offline

#142 2020-10-07 14:59:31

sleekmason
zoom
Registered: 2018-05-22
Posts: 1,103
Website

Re: Handy command-line stuff for terminals or scripts

Everybody needs a one-liner toggle for menus and keybinds:)

bash -c 'if ! pkill -x compton; then exec compton; fi'

Use it for compton, conky, xclip, etc.. No need to script a toggle!

Offline

#143 2020-10-20 02:58:59

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,560
Website

Re: Handy command-line stuff for terminals or scripts

Search YouTube without a browser now has its own thread.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#144 2020-10-20 05:57:24

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Handy command-line stuff for terminals or scripts

^ Thanks!

Offline

#145 2020-10-25 05:35:28

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,560
Website

Re: Handy command-line stuff for terminals or scripts

sleekmason wrote:

Everybody needs a one-liner toggle for menus and keybinds:)

bash -c 'if ! pkill -x compton; then exec compton; fi'

Use it for compton, conky, xclip, etc.. No need to script a toggle!

Nice!

I would use the boolean || operator myself, just to save some typing:

bash -c 'pkill -x compton || exec compton'

but it's mostly a matter of personal taste. (It's easy to mess up with && and || in anything more complicated.)

BTW For the specific case of compton, BL users might prefer 'bl-compositor --restart' which will preserve any startup options that might have been set in /etc/bunsen/compton-startup.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#146 2020-10-25 13:39:46

vasa1
Member
Registered: 2015-09-29
Posts: 204

Re: Handy command-line stuff for terminals or scripts

johnraff wrote:

...

bash -c 'pkill -x compton || exec compton'

...

It seems to work as well without exec.


Using the Openbox (3.5.2) session of Lubuntu 14.04 LTS but very interested in BL :)

Offline

#147 2020-10-25 16:01:11

sleekmason
zoom
Registered: 2018-05-22
Posts: 1,103
Website

Re: Handy command-line stuff for terminals or scripts

johnraff wrote:
sleekmason wrote:

Everybody needs a one-liner toggle for menus and keybinds:)

bash -c 'if ! pkill -x compton; then exec compton; fi'

Use it for compton, conky, xclip, etc.. No need to script a toggle!

Nice!

I would use the boolean || operator myself, just to save some typing:

bash -c 'pkill -x compton || exec compton'

but it's mostly a matter of personal taste. (It's easy to mess up with && and || in anything more complicated.)

BTW For the specific case of compton, BL users might prefer 'bl-compositor --restart' which will preserve any startup options that might have been set in /etc/bunsen/compton-startup.

Oh, that is excellent!  Simpler the better. I know nothing but the scraps I pick up:)

vasa1 wrote:

It seems to work as well without exec.

Good catch! smile 

So why won't this work as well for the hotcorners script I grabbed from CB?  I'm guessing something to do with the --daemon part?  I've tried

bash -c 'pkill -x ld-hotcorners --daemon || exec ld-hotcorners --daemon'

Actually the first code, and then every variation I could think up but no go. I wound up just making two menu entries instead. Works but not as neat:)  enclosed/bracketed somehow?

Offline

#148 2020-10-25 18:03:06

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: Handy command-line stuff for terminals or scripts

^ Try quoting the commands. From man pkill

-x, --exact
              Only  match  processes  whose  names (or command line if -f is specified) exactly
              match the pattern.

So, I surmise:

bash -c 'pkill -x "ld-hotcorners --daemon" || "ld-hotcorners --daemon"'

Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#149 2020-10-25 19:27:48

sleekmason
zoom
Registered: 2018-05-22
Posts: 1,103
Website

Re: Handy command-line stuff for terminals or scripts

damo wrote:

^ Try quoting the commands. From man pkill

-x, --exact
              Only  match  processes  whose  names (or command line if -f is specified) exactly
              match the pattern.

So, I surmise:

bash -c 'pkill -x "ld-hotcorners --daemon" || "ld-hotcorners --daemon"'

You would think so right? But no, not this, nor  pkill -f, nor using just killall.  The hotcorners become enabled, and will not disable again.

Offline

#150 2020-10-25 20:22:17

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: Handy command-line stuff for terminals or scripts

Is "ld-hotcorners --daemon" the actual full command that was used to start it?

bl-hotcorners has

-k, --kill    attempt to kill any running instances

Does ld-hotcorners have the same?


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#151 2020-10-25 20:58:56

sleekmason
zoom
Registered: 2018-05-22
Posts: 1,103
Website

Re: Handy command-line stuff for terminals or scripts

Yes indeed! Didn't think it would have it's own kill switch. Is that common?  more good learning:)

ld-hotcorners --daemon &
pkill -f ld-hotcorners

Is how I am starting/stopping it separately in the menu.

Just tried:

bash -c 'ld-hotcorners --kill || exec ld-hotcorners --daemon &'

and:

bash -c 'pkill -9 -f ld-hotcorners || exec "ld-hotcorners --daemon &"' 

Both worked killing the daemon but would not let it start! 
I tried these with/without quotes, and without the & at the end as well.
Left these like this because at least they killed it:) Progress!

Offline

#152 2020-10-25 21:09:11

sleekmason
zoom
Registered: 2018-05-22
Posts: 1,103
Website

Re: Handy command-line stuff for terminals or scripts

Okay, if I add the quotes to:

"ld-hotcorners --kill"

*edit (or on both sides).
It comes on and stays on again. Ugh.

Last edited by sleekmason (2020-10-25 21:17:16)

Offline

#153 2020-10-26 06:58:15

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Handy command-line stuff for terminals or scripts

sleekmason wrote:
bash -c 'pkill -9 -f ld-hotcorners || exec "ld-hotcorners --daemon &"' 
man pkill wrote:

-f, --full
The pattern is normally only matched against the process name. When -f is set, the
full command line is used.

That's what was missing before.
And trust me, it does kill without specifying the signal. Which should be TERM, not KILL anyhow.
You can always test what pkill would kill with pgrep first.
And be careful with pkill - the wrong expression, and it will happily kill everything it has permissions for.
Usually you should just catch the pid of the daemon when you start it, and later just kill that with "kill $ld_hotcorners_pid" or some such. Many daemons also create a pidfile.

sleekmason wrote:
exec "ld-hotcorners --daemon &"

This won't work.
Try it in your terminal:

$> echo bla
bla
$> "echo bla &"
bash: echo bla &: command not found
$> 

Do you need the & at the end? "--daemon" means daemonize anyhow, no? "exec" means "exit from shell & execute" in this case.

exec ld-hotcorners --daemon

(no quotes!) should suffice.

Last edited by ohnonot (2020-10-26 07:04:02)

Offline

#154 2020-10-26 15:26:52

sleekmason
zoom
Registered: 2018-05-22
Posts: 1,103
Website

Re: Handy command-line stuff for terminals or scripts

If I have you correctly,

bash -c 'pkill -9 -f ld-hotcorners || exec ld-hotcorners --daemon' 

Should work, but doesn't.

bash -c 'ld-hotcorners --kill || exec ld-hotcorners --daemon' 

gives same. 
If I turn ld-hotcorners on first, either of these will kill it, but nothing will start it.

*Side note:)

sleekmason@ai:~$ echo blah
blah
sleekmason@ai:~$ echo blah &
[1] 14065
blah

Wait what?  Did it just start a daemon for blah??  lol:)

Offline

#155 2020-10-26 16:31:07

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,011

Re: Handy command-line stuff for terminals or scripts

I use this to "kill" a specific conky.
NOTE: what is between the " " is the EXACT command used to start that conky:

pkill -xf "conky -c /media/5/Conky/time.conky" &

and this will kill it and restart it:

pkill -xf "conky -c /media/5/Conky/time.conky" && conky -c /media/5/Conky/time.conky &

I also have a SSC.sh file to Start|Stop Conky, various ones, that might help you, adapt it for your need:

#!/bin/bash
## Original idea by: GrouchyGaijin
## This idea by: Stinkeye - Jan 2013
## With another tweak by: arclance
## Final tweak by: Sector11
## click to start, click to stop

if pgrep -f "conky -q -c /media/5/Conky/easysid/MechClock/conkyrc_clock"
then
	pkill -xf "conky -q -c /media/5/Conky/easysid/MechClock/conkyrc_clock"
else
	conky -q -c "/media/5/Conky/easysid/MechClock/conkyrc_clock"
fi

It checks to see if the conky is running:
if yes - it kills it
if no - it starts it

Worth a try. 
Remember the part inside the " " are the exact command to run the program.


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#156 2020-10-26 21:51:13

sleekmason
zoom
Registered: 2018-05-22
Posts: 1,103
Website

Re: Handy command-line stuff for terminals or scripts

bash -c 'pkill -9 -f ld-hotcorners || exec ld-hotcorners --daemon' 

Of interest is that both these commands work separately in a terminal, adding & at the end only necessary to close the terminal.

If that is the case, It seems like somehow the commands are not being separated?

Same thing if I try the whole command in a terminal. And of interest is that it wont activate ld-hotcorners, but will shut it back off if already on.

Sector11 wrote:

Worth a try.
Remember the part inside the " " are the exact command to run the program.

Yes indeed!  Ran through all of yours as well. Looked promising .  Went through it very carefully, and then every variation I could think of:)  Thank you for giving it a shot. No worries on whether I get this or not, but fascinating that it won't work!

The only point of this was to try to get away without using a script, so I haven't tried yet, but it looks like I may have to:)

Offline

#157 2020-10-27 03:15:51

vasa1
Member
Registered: 2015-09-29
Posts: 204

Re: Handy command-line stuff for terminals or scripts

@sleekmason, I don't know if this is relevant to your needs (or has already been mentioned) but rc.xml requires that "&" be entered as "&".

For example, I use the keybind "C-W-A" to run

sh -c "scrot --focused --pointer $HOME/Pictures/$(date +%Y%m%d%H%M%S).png && paplay $HOME/Dropbox/Sounds/camera-shutter.oga"

Using the Openbox (3.5.2) session of Lubuntu 14.04 LTS but very interested in BL :)

Offline

#158 2020-10-29 06:54:53

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Handy command-line stuff for terminals or scripts

vasa1 wrote:

@sleekmason, I don't know if this is relevant to your needs (or has already been mentioned) but rc.xml requires that "&" be entered as "&".

Take my upvote!

@sleekmason: here's a nice guide for bash scripting.

Offline

#159 2020-10-29 13:15:47

sleekmason
zoom
Registered: 2018-05-22
Posts: 1,103
Website

Re: Handy command-line stuff for terminals or scripts

vasa1 wrote:

@sleekmason, I don't know if this is relevant to your needs (or has already been mentioned) but rc.xml requires that "&" be entered as "&".

For example, I use the keybind "C-W-A" to run

sh -c "scrot --focused --pointer $HOME/Pictures/$(date +%Y%m%d%H%M%S).png && paplay $HOME/Dropbox/Sounds/camera-shutter.oga"

Howdy! Tried this as well:)
Here is where I am at the moment:

sleekmason@ai:~$ exec "ld-hotcorners" --daemon &
[1] 4505
sleekmason@ai:~$ pkill -9 -f "ld-hotcorners --daemon"
sleekmason@ai:~$ exec "ld-hotcorners" --daemon &
[2] 4520
[1]   Killed                  exec "ld-hotcorners" --daemon
sleekmason@ai:~$ pkill -9 -f "ld-hotcorners --daemon"

So, individually they work. . .

Yay! Great! so:

sleekmason@ai:~$ bash -c 'pkill -9 -f "ld-hotcorners --daemon" || exec "ld-hotcorners" --daemon'
[2]+  Killed                  exec "ld-hotcorners" --daemon
Killed
sleekmason@ai:~$ bash -c 'pkill -9 -f "ld-hotcorners --daemon" || exec "ld-hotcorners" --daemon'
Killed

Keeps killing it, as if the two commands are connected. Jeez.



ohnonot wrote:

@sleekmason: here's a nice guide for bash scripting.

Yes! I think I'm finally ready for this.  A bit backwards I know, but here I am.  Thank you:) My guess is I will just have to script it, but I ain't giving up! That does not mean I won't take the easy answer if you happen to see it.  big_smile

Offline

#160 2020-11-02 03:25:19

sleekmason
zoom
Registered: 2018-05-22
Posts: 1,103
Website

Re: Handy command-line stuff for terminals or scripts

Here is the toggle solution:

#!/bin/bash
if pgrep -f ld-hotcorners > /dev/null; then
    pkill -9 -f ld-hotcorners
else
    ld-hotcorners --daemon &
fi

Fairly straightforward I suppose. Don't know why the one liner wouldn't work.
@ohnonot, the bash guide is good. Thanks:)

*EDIT Do NOT use pkill -9 - Bad practice. The correct code is:

#!/bin/bash
if pgrep -f ld-hotcorners > /dev/null; then
    pkill -f ld-hotcorners
else
    ld-hotcorners --daemon &
fi

Last edited by sleekmason (2020-11-02 13:23:46)

Offline

Board footer

Powered by FluxBB