You are not logged in.

#1 2025-06-30 19:37:14

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

Start a script on resume. [SOLVED]

When I 'suspend' my computer I want my conky's to restart when I "resume" my computer.

Found this little tutorial: How To Run Scripts And Commands On Suspend And Resume on Linux found there

And have created this bash script and  set it to run.

#!bin/bash
## /lib/systemd/system-sleep/pre-resume.sh

## On the next line, add the “if” portion of the script.

if [ "${1}" == "pre" ]; then
## replace with command OR
## nothing goes here

## With that bit of code pasted into the bash script,
## move down and paste the “else if” section.

elif [ "${1}" == "post" ]; then
sh /media/5/Conky/OBMenuS/S11_Current.sh
fi

## Once again, it’s OK to write anything under the
## “elif” line. As long as it is a normal command
## operation systemd and bash will run it.

BUT it does not work.  Any help appreciated.


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#2 2025-06-30 20:26:02

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 2,658

Re: Start a script on resume. [SOLVED]

Did you remember to make the script executable?


You must unlearn what you have learned.
    -- yoda

Offline

#3 2025-06-30 21:49:36

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

Re: Start a script on resume. [SOLVED]

OH, yes I forgot to mention that.  Yrs it was: chmod +x 'ed   big_smile

chmod +x /lib/systemd/system-sleep/pre-resume.sh

Should have mentioned that.

Before you ask: Yes as root!  wink


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#4 2025-06-30 22:14:23

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 2,658

Re: Start a script on resume. [SOLVED]

Is that capital "S" in OBMenuS a typo?

You are the king, after all.   smile


You must unlearn what you have learned.
    -- yoda

Offline

#5 2025-06-30 22:22:27

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

Re: Start a script on resume. [SOLVED]

PackRat wrote:

Is that capital "S" in OBMenuS a typo?

You are the king, after all.   smile

Yes, I am The Tpyo Knig but no that is correct:
250630-191918.jpg
It was "copy/pasted" into place.
Been in that directory since #! dayz.


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#6 2025-06-30 22:31:02

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 2,658

Re: Start a script on resume. [SOLVED]

Change

#!bin/bash

to

#!/bin/bash

https://tldp.org/LDP/abs/html/sha-bang.html

It was "copy/pasted" into place.

You can also try manually entering that part in case your copy-paste is introducing something bash doesn't like.


You must unlearn what you have learned.
    -- yoda

Offline

#7 2025-06-30 22:33:38

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

Re: Start a script on resume. [SOLVED]

There was a typo worthy of The Tpyo Knig though, first line:

#!bin/bash

changed to:

#!/bin/bash

stupid little / -> however the change made no difference.


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#8 2025-06-30 22:51:13

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 2,658

Re: Start a script on resume. [SOLVED]

That typo is in the section of the blog you were reading. The hazards of cut/paste.

I can't spot anything else in your script. I'm assuming you have been running the S11_Current.sh for a while so no errors in that.

Edit - Read the comments at the end of that article. Looks like some mediocre scripting by the author may be the culprit.


You must unlearn what you have learned.
    -- yoda

Offline

#9 2025-06-30 23:12:45

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

Re: Start a script on resume. [SOLVED]

The hazards of cut/paste.

Trust me huh!

S11_Current.sh is in my OB autostart file

{snip}
nitrogen --restore &

fbpanel &
(sleep 1s && artha) &
(sleep 1s && volumeicon) &
sleep 2s && /media/5/Conky/OBMenuS/S11_Current.sh &
picom

exit

Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#10 2025-07-01 01:31:07

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

Re: Start a script on resume. [SOLVED]

Tested this with my data - didn't work either.  From here

#!/bin/sh
case $1 in
  post)
    /bin/runme
  ;;
esac

Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#11 2025-07-01 06:52:25

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

Re: Start a script on resume. [SOLVED]

Looking at the script, it seems to need running with either 'pre' or 'post' as an argument.
EDIT OK I see this is a systemd arrangement.

But before getting to that, why do you even need to restart your conky session after suspending, then restoring?

I just did a trial suspend, and after restoring, all my conkys (and everything else) were still running just like before with no need for any restart scripts.

Last edited by johnraff (2025-07-01 06:58:24)


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

#12 2025-07-01 09:31:30

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 2,695

Re: Start a script on resume. [SOLVED]

^To me, it's like shooting at sparrows with cannons.  big_smile

In my opinion the script should be in $HOME, because conky etc. are started by the $USER and not by the system. That's probably the reason why it doesn't work.

Offline

#13 2025-07-01 17:06:06

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

Re: Start a script on resume. [SOLVED]

Did not think I'd have to explain WHY I want to do something, but here's the why:

I have 3 conkys that open in "windows" when I POWER ON.
I read them, then shut them down to get them out of the way:

1. dates to remember,
2. a Calendar with reminders, and
3. a conky that shows my keyboard shorcuts.

THEY do not restart after resume, the running conkys of course like any other app running when you suspend will still be there on resume.

IF I can get this working I will just run the three conkys I want but it was easier to use just one line in my OP.

Correct John, it is something that is controlled by systend

When I search for how to start a file after resuming from suspend every site on the web says I have to use the file in: /lib/systemd/system-sleep/

In the end it will be like this:

#!/bin/bash

if [ "${1}" == "pre" ]; then

elif [ "${1}" == "post" ]; then

sh conky -q -c /media/5/Conky/S11_Keybinds.conky &
sh conky -q -c /media/5/Conky/S11_Rem_Cal.conky &
sh conky -q -c /media/5/Conky/S11_Dates.conky &

fi

See them here
S11 Dates stretched almost to the bottom of the screen
Retired | Reminders stretched dow at least double what you see
Keybinds is the actual size

When I resume my PC in the morning I'd like to see those three conkys as if I had Powered Down| Powered Up.


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#14 2025-07-02 02:08:02

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

Re: Start a script on resume. [SOLVED]

Then I think Unklar is right that you need to be running the conky script inside your user session.
But, agreed, it looks a bit tricky to trigger it from a system event like restoring from suspend.

The BL upgrades notifier script faces a similar problem in how a system operation (apt update) can run a user action (display a notification). I'll have a look - maybe you can use it to run a script of your own, ie those startup conkys...

...(later) maybe the runuser command on line 84 here can be adapted?
(runuser comes with util-linux which you probably have already)

https://github.com/BunsenLabs/bunsen-ap … adcast#L84

You need a way to get the value of $DISPLAY for your user session. If it's always the same maybe it can just be hard-coded. Otherwise the systemd script needs to find the $DISPLAY that belongs to your username, before calling runuser. It might not be very hard.


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

#15 2025-07-02 13:12:42

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

Re: Start a script on resume. [SOLVED]

unklar wrote:

^To me, it's like shooting at sparrows with cannons.  big_smile

In my opinion the script should be in $HOME, because conky etc. are started by the $USER and not by the system. That's probably the reason why it doesn't work.

My apologies for not responding and being a bit arrogant to everyone about why I want this done.

EVERYWHERE I looked talks "systemd".  You  are correct it is a $USER problem.

johnraff wrote:

You need a way to get the value of $DISPLAY for your user session. If it's always the same maybe it can just be hard-coded. Otherwise the systemd script needs to find the $DISPLAY that belongs to your username, before calling runuser. It might not be very hard.

That is WAY over my head.  But it is obvious that it it us a $USER thing that is not going to happen anytime soon.

I'll just have to 'remember' to restart my conkys after a resume, and that's where my forgetter kicks in..


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#16 2025-07-02 17:42:50

marens
Member
From: World without M$
Registered: 2023-02-02
Posts: 872

Re: Start a script on resume. [SOLVED]

johnraff wrote:

I just did a trial suspend, and after restoring, all my conkys (and everything else) were still running just like before with no need for any restart scripts.

It's the same here.

If that doesn't work, I would probably try creating an executable script  /lib/systemd/system-sleep/start_conkys_after_suspend:

#!/bin/bash

if [ "${1}" == "pre" ]; then
 
    echo "we are suspending at $(date)..." > $HOME/conky_log
      
  elif [ "${1}" == "post" ]; then

    killall conky

## Delayed start (if necessary)
    sleep 10

## We need to know the path where conky is located and the name of conky
 # If all the conkys are in the same folder, things become simpler as only one cd command is required (at the beginning).

    cd "/path/to/conky/folder1"
    conky -c "/path/to/conky_name1" &

    cd "/path/to/conky/folder2"
    conky -c "/path/to/conky_name2" &

    cd "/path/to/conky/folder3"
    conky -c "/path/to/conky_name3" &

    cd "/path/to/conky/folder4"
    conky -c "/path/to/conky_name4" &

    echo "...and we are back from $(date)" >> $HOME/conky_log

fi

Note *
These parts (path) need to be replaced with the right ones:

    cd "/path/to/conky/folder1"
    conky -c "/path/to/conky_name1" &

    ---

Then Reboot  >  Suspend.
After restoring, the start_conkys_after_suspend  script should run.

Open and check the ~/conky_log  file.

Last edited by marens (2025-07-02 20:08:11)


If people would know how little brain is ruling the world, they would die of fear.

Offline

#17 2025-07-03 00:35:01

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

Re: Start a script on resume. [SOLVED]

@ marens

If you look at my OP you will see I did the:

/lib/systemd/system-sleep/pre-resume.sh

With nothing between "pre" as it was not required.

Your example IF it worked would KILL the 7 conkys that do show on 'resume'  - I do not want that.  That's why I was testing with my known script that KILLS all conkys and then runs them all again.

From one of the sites visited I saw this:

## Once again, it’s OK to write anything under the
## “elif” line. As long as it is a normal command
## operation systemd and bash will run it.

which does not work on my system and from what I have see on many others.

My 'suposedly' working file still exists:
/lib/systemd/system-sleep/pre-resume.sh

and my computer has been rebooted, put to sleep and resumed many times.

It's not working.

EDIT:  I tried the:

echo "we are suspending at $(date)..." > $HOME/conky_log

no log file was created.


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#18 2025-07-03 07:42:53

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

Re: Start a script on resume. [SOLVED]

OK you piqued my interest here - this might be something I or another user might want to do in future, and I think I've got a solution. It's working for me anyway, but it's not simple. You have to make three scripts.

First here's the longest bit, bl-run-user, which was hacked from bl-run-broadcast. There should be no need to edit this file. Copy/paste it anywhere in you like - it doesn't have to be a system file - but make it executable:

#!/bin/bash
#
#    bl-run-user
#    utility for root to run a command as a current X user
#

HELP="bl-run-user is a script for a root process
to run a command as a current X user, on each of that user's DISPLAYs.

On each DISPLAY, the command is run in a bash shell,
forked and disowned, so the parent process should not hang,
even if child processes continue running.

Usage: bl-run-user <username> <command> [<arguments>]

Optional arguments:
    -h | --help    Show this message

This script must be run as root.

NOTE Any command and arguments can be passed, but this utility was intended
for relatively short-lived notification applications like notify-send or yad.
Because the spawned processes are disowned, there will be no way to
check their return values on exit.

EXAMPLE:

bl-run-user someuser notify-send 'System Message' 'Something happened that you should know about.'

"

error_exit() {
    echo "$0 error: $1" >&2
    exit 1
}

case $1 in
--help|-h)
    echo "$HELP"
    exit
    ;;
'')
    echo "${0}: no command was passed" >&2
    exit 1
    ;;
esac

user=$1
userid=$(id -u "$user")
(( userid >= 1000 )) || error_exit "$1 is not a normal user"
shift

founduser=false
for i in $(users);do # "users" command output
    [[ $i = "$user" ]] && {
        founduser=true
        break
    }
done

[[ $founduser = true ]] || error_exit "user $user is not logged in"
command -v "$1" >/dev/null || error_exit "cannot find command $1"

[[ $( id -u ) -eq 0 ]] || error_exit "This script must be run as root."

declare -A displays
displays=()

for i in $(ps e -u "$user" | sed -rn 's/.* DISPLAY=(:[0-9]+).*/\1/p');do
    displays[$i]=1
done

for d in "${!displays[@]}";do
	runuser -l "${user}" --shell /usr/bin/bash -c "set -m; DISPLAY=${d} XDG_RUNTIME_DIR=/run/user/$userid $(printf '%q ' "$@" ) >/dev/null 2>&1 & disown; set +m;"
done

exit

Here's my conky test script. I don't need to tell you anything about what to put in that. Any script ought to work OK:

#!/bin/bash

conky -q -c /home/john/.config/conky/bigClock-lithium-light-conky.conf &
conky -q -c /home/john/.config/conky/BL-Def-Cal-conky.conf &

And finally here's what I put in /usr/lib/systemd/system-sleep/ I called it user-resume but any filename is OK. Make this executable too, and of course change "john" to your username, and the paths to bl-run-user and your conky script to whatever you used:

#!/bin/sh

case $1 in
  post)
    /home/john/scripts/bl-run-user john /home/john/scripts/conky-test-script
    ;;
esac

(Don't forget that bl-run-user needs to be passed the username before the command (+ arguments) to run.)
Both the script paths need to be full because there's no guarantee that the root script user-resume will know your $PATH.

You (and anyone else) can use that bl-run-user script any time a root process needs to run something inside a user session.

Last edited by johnraff (2025-07-03 23:47:33)


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

#19 2025-07-03 12:43:33

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

Re: Start a script on resume. [SOLVED]

On my way out the door.
Looks good John, will get at it after my test.


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#20 2025-07-03 13:28:50

marens
Member
From: World without M$
Registered: 2023-02-02
Posts: 872

Re: Start a script on resume. [SOLVED]

johnraff wrote:

All the script paths need to be full because there's no guarantee that the root script user-resume will know your $PATH.

I can confirm that.

Ten years ago I used Conky Manager (@teejee2008 - GitHub):
https://github.com/teejee2008/conky-manager

Unfortunately, Conky Manager has been down for a long time, but I still have the file (script) ~/.conky/conky-startup.sh that the application created:

sleep 12s
killall conky
cd "/home/marens/.conky/SM*Gotham2LX"
conky -c "/home/marens/.conky/SM*Gotham2LX/SM*Gotham2LX" &
cd "/home/marens/.conky/SM*OneLine"
conky -c "/home/marens/.conky/SM*OneLine/SM*OneLine" &
cd "/home/marens/.conky/SM*SimpleLX"
conky -c "/home/marens/.conky/SM*SimpleLX/SM*SimpleLX" &

The full path is always used here.

P.S.
Interestingly, each conky is in its own subfolder.
I think it's a good idea because I use a lot of images and scripts and I can find them easily.


If people would know how little brain is ruling the world, they would die of fear.

Offline

Board footer

Powered by FluxBB