You are not logged in.

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

sleekmason
Member
Registered: 2018-05-22
Posts: 266

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!

Online

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

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,419
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), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

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

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

Re: Handy command-line stuff for terminals or scripts

^ Thanks!


Search youtube without a brwoser: repo | thread
BL quote proposals to this thread please.
my repos / my repos

Offline

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

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,419
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), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

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

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

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 :)

Online

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

sleekmason
Member
Registered: 2018-05-22
Posts: 266

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?

Online

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

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

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

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

sleekmason
Member
Registered: 2018-05-22
Posts: 266

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.

Online

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

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

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

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

sleekmason
Member
Registered: 2018-05-22
Posts: 266

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!

Online

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

sleekmason
Member
Registered: 2018-05-22
Posts: 266

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)

Online

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

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

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)


Search youtube without a brwoser: repo | thread
BL quote proposals to this thread please.
my repos / my repos

Offline

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

sleekmason
Member
Registered: 2018-05-22
Posts: 266

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:)

Online

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

Sector11
Conky 1.9er Mod Squid
From: Upstairs
Registered: 2015-08-20
Posts: 6,468

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.


The sun will never set if you keep walking towards it. - my son
Being positive doesn't understand physics.
_______________________________
Debian 10 Buster = SharpBang ♯!

Offline

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

sleekmason
Member
Registered: 2018-05-22
Posts: 266

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:)

Online

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

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

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 :)

Online

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

ohnonot
...again
Registered: 2015-09-29
Posts: 5,022
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 "&".

Take my upvote!

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


Search youtube without a brwoser: repo | thread
BL quote proposals to this thread please.
my repos / my repos

Offline

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

sleekmason
Member
Registered: 2018-05-22
Posts: 266

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

Online

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

sleekmason
Member
Registered: 2018-05-22
Posts: 266

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)

Online

#170 2020-11-02 04:02:34

Sector11
Conky 1.9er Mod Squid
From: Upstairs
Registered: 2015-08-20
Posts: 6,468

Re: Handy command-line stuff for terminals or scripts

sleekmason wrote:

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:)

Which is very close to this.

Gotta love happy endings.


The sun will never set if you keep walking towards it. - my son
Being positive doesn't understand physics.
_______________________________
Debian 10 Buster = SharpBang ♯!

Offline

#171 2020-11-02 06:53:30

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

Re: Handy command-line stuff for terminals or scripts

Thou shalt not (p)kill -9.


Search youtube without a brwoser: repo | thread
BL quote proposals to this thread please.
my repos / my repos

Offline

#172 2020-11-02 13:19:17

sleekmason
Member
Registered: 2018-05-22
Posts: 266

Re: Handy command-line stuff for terminals or scripts

@Sector11  Yes! very close:)

@ohnonot Fixed and done!  Lol.  Wasn't about to touch it after I got it working. I had grabbed:

pkill -9 -f ld-hotcorners

from the ld-hotcorners script itself.  What does the -9 do?  man pkill doesn't seem to have that as an option.  Process #?

Last edited by sleekmason (2020-11-03 01:29:32)

Online

#173 2020-11-02 14:21:32

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

Re: Handy command-line stuff for terminals or scripts

sleekmason wrote:

What does the -9 do?  man pkill doesn't seem to have that as an option.  Process #?

SIGKILL

man kill

A full list of SIG commands can be seen if you run htop, and use F9.


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

#174 2020-11-02 15:51:53

Sector11
Conky 1.9er Mod Squid
From: Upstairs
Registered: 2015-08-20
Posts: 6,468

Re: Handy command-line stuff for terminals or scripts

Ot just list in the kill command:

 02 Nov 20 @ 12:48:46 ~
   $ kill -l
 1) SIGHUP	 2) SIGINT	 3) SIGQUIT	 4) SIGILL	 5) SIGTRAP
 6) SIGABRT	 7) SIGBUS	 8) SIGFPE	 9) SIGKILL	10) SIGUSR1
11) SIGSEGV	12) SIGUSR2	13) SIGPIPE	14) SIGALRM	15) SIGTERM
16) SIGSTKFLT	17) SIGCHLD	18) SIGCONT	19) SIGSTOP	20) SIGTSTP
21) SIGTTIN	22) SIGTTOU	23) SIGURG	24) SIGXCPU	25) SIGXFSZ
26) SIGVTALRM	27) SIGPROF	28) SIGWINCH	29) SIGIO	30) SIGPWR
31) SIGSYS	34) SIGRTMIN	35) SIGRTMIN+1	36) SIGRTMIN+2	37) SIGRTMIN+3
38) SIGRTMIN+4	39) SIGRTMIN+5	40) SIGRTMIN+6	41) SIGRTMIN+7	42) SIGRTMIN+8
43) SIGRTMIN+9	44) SIGRTMIN+10	45) SIGRTMIN+11	46) SIGRTMIN+12	47) SIGRTMIN+13
48) SIGRTMIN+14	49) SIGRTMIN+15	50) SIGRTMAX-14	51) SIGRTMAX-13	52) SIGRTMAX-12
53) SIGRTMAX-11	54) SIGRTMAX-10	55) SIGRTMAX-9	56) SIGRTMAX-8	57) SIGRTMAX-7
58) SIGRTMAX-6	59) SIGRTMAX-5	60) SIGRTMAX-4	61) SIGRTMAX-3	62) SIGRTMAX-2
63) SIGRTMAX-1	64) SIGRTMAX	
 
 02 Nov 20 @ 12:50:39 ~
   $ 

More reading: Why should I not use 'kill -9' / SIGKILL


The sun will never set if you keep walking towards it. - my son
Being positive doesn't understand physics.
_______________________________
Debian 10 Buster = SharpBang ♯!

Offline

#175 2020-11-02 17:36:06

sleekmason
Member
Registered: 2018-05-22
Posts: 266

Re: Handy command-line stuff for terminals or scripts

Wow!  Have not seen all of those before now. Thank you both for the information:)

From the link:

Under the covers even trivial-seeming programs do all sorts of transactional work that they need to clean up from before terminating (think of the finally block in Java and other programming languages), such as closing resource handles, deleting temporary files, and flushing data from memory to disk. You cannot anticipate when a program might be doing something like this.

If you're lucky you won't notice anything amiss if you send a SIGKILL, but you can't be lucky forever, and you may not know anything's gone wrong until it's too late to recover what's been lost.

That sums it up nicely.

Online

Board footer

Powered by FluxBB