You are not logged in.

#176 2020-11-02 20:47:11

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

Re: Handy command-line stuff for terminals or scripts

Notice my little script does NOT use "pkill -9".

If running shut it down
If not running, start it up  smile


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

Offline

#177 2020-11-03 01:33:15

sleekmason
zoom
From: Ozarks
Registered: 2018-05-22
Posts: 510
Website

Re: Handy command-line stuff for terminals or scripts

*Ouch! Just saw where I may have inferred such inadvertently. Changed to reflect the ld-hotcorners script;)

Offline

#178 2020-11-03 07:03:46

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

Re: Handy command-line stuff for terminals or scripts

Sector11 wrote:

...
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.

Looks like the "pgrep" bit can be left out:

#!/bin/bash

pkill -xf "conky -c /path/to/conky" || conky -c "/path/to/conky"

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

Offline

#179 2020-11-06 22:08:11

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

Re: Handy command-line stuff for terminals or scripts

sleekmason wrote:

What does the -9 do?

http://turnoff.us/image/en/dont-sigkill.png


Please use CODE tags for code.
Search youtube without a browser: repo | thread
BL quote proposals to this thread please.
my repos / my repos

Offline

#180 2020-11-07 02:27:50

sleekmason
zoom
From: Ozarks
Registered: 2018-05-22
Posts: 510
Website

Re: Handy command-line stuff for terminals or scripts

ohnonot wrote:
sleekmason wrote:

What does the -9 do?

http://turnoff.us/image/en/dont-sigkill.png

Ha!  This is good:)

Offline

#181 2020-12-11 18:30:27

sleekmason
zoom
From: Ozarks
Registered: 2018-05-22
Posts: 510
Website

Re: Handy command-line stuff for terminals or scripts

Made this bit to find which window manager to display in Conky.

wmctrl -m | head -n1 | cut -d" " -f2

Offline

#182 2020-12-11 20:37:05

rbh
Member
From: Sweden/Vasterbotten/Rusfors
Registered: 2016-08-11
Posts: 931

Re: Handy command-line stuff for terminals or scripts

How do you manage the need to run as root or with sudo, when in conky?


// Regards rbh

Offline

#183 2020-12-11 21:17:02

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

Re: Handy command-line stuff for terminals or scripts

rbh wrote:

How do you manage the need to run as root or with sudo, when in conky?

It comes down to being able to execute commands with superuser privileges without the need of entering a password (interactively).
Several approaches exist: with PAM I guess, or with adding certain commands to your sudoers config files under /etc.
For the latter, see: https://wiki.archlinux.org/index.php/Su … le_entries


Please use CODE tags for code.
Search youtube without a browser: repo | thread
BL quote proposals to this thread please.
my repos / my repos

Offline

#184 2021-02-15 07:18:53

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

Re: Handy command-line stuff for terminals or scripts

I was playing around with using conky to display a visual notification from a shell script.
Conky can read config files from stdin! That opens a lot of possibilities...
Proof of concept: find your mouse cursor - displays a red square around your pointer for 2 seconds. Requires xdotool.

#!/bin/sh

showtime=2 # seconds
eval $(xdotool getmouselocation --shell)

cat <<EOF | conky -c - & conkypid=$!
conky.config = {
own_window = true,
own_window_transparent = false,
own_window_colour = '#ff0000',
own_window_hints = 'undecorated,skip_taskbar,skip_pager,sticky',
update_interval = 1,
double_buffer = true,
minimum_width = 20,
minimum_height = 20,
maximum_width = 20,
alignment = 'top_left',
gap_x = $X,
gap_y = $Y,
draw_borders = true,
draw_outline = false,
draw_shades = false,
border_width = 4,
border_outer_margin = 2,
default_color = '#ffffff',
};
conky.text = [[]];
EOF

# total_run_times is unreliable, therefore:
sleep "$showtime"
kill $conkypid

Please use CODE tags for code.
Search youtube without a browser: repo | thread
BL quote proposals to this thread please.
my repos / my repos

Offline

#185 2021-02-15 09:18:36

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,753
Website

Re: Handy command-line stuff for terminals or scripts

ohnonot wrote:

I was playing around with using conky to display a visual notification from a shell script.
Conky can read config files from stdin! That opens a lot of possibilities...

Nice find!

---
Other topic:
sh -c '...some code...'
is sometimes useful when you want to run a snippet of shell code from a menu item, Thunar custom action or tint2 or any other situation that doesn't support shell syntax. sh (or bash if you need the extra features) is the command to run, and everything after the -c is just a parameter, so the launcher doesn't have to interpret it at all, just send it to the shell. It's highly advisable to wrap that shell code in single quotes so it won't be touched by anything else.

But this is already well known. Possibly slightly less well known is that you can pass positional parameters to that code snippet, just as if it was a function or separate script in a file.

Try this in a terminal:

sh -c 'echo "First: $1, Second: $2"' _ one two

Just a minute, what's that _ doing? That gets passed as $0, which usually means the shell name or script name. Here it's a placeholder (still accessible as $0) that gets used in error messages:

sh -c  'ecko "First: $1, Second: $2"' mycode one two

So sometimes there is value in using a meaningful string in the zeroth place, but usually _ is enough.

More reading:
https://superuser.com/questions/1526229 … ll-code-sh


...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

Board footer

Powered by FluxBB