You are not logged in.

#1 2020-01-02 21:09:29

Uooops
Member
Registered: 2019-07-08
Posts: 15

[SOLVED] Sync script at the end of the session

(Please, move this topic if it's not its place)

Hello.

I'm trying to sync some files between two computers at the beginnig and at the end of session. I've get the first thing done but I don't know how to do the last.

I've read that setting the script in systemd could be an option but I would like to know if there are more possibilities.

Any suggestion?

Thanks

Last edited by Uooops (2020-01-03 17:59:36)

Offline

#2 2020-01-02 23:44:47

damo
....moderator....
Registered: 2015-08-20
Posts: 5,403

Re: [SOLVED] Sync script at the end of the session

How are you exiting the session?

You can create a systemd shutdown script (plenty of HowTos if you search the web), or add a command to your bl-exit 'poweroff' procedure.

Helium uses a python bl-exit script, so I reckon you would edit the relevant line in def main()

action = "myscript.sh;poweroff"

Lithium uses a bash script, so maybe edit bl-exit where there are references to "logoutctl poweroff"

myscript.sh;logoutctl poweroff

Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#3 2020-01-03 00:10:54

Uooops
Member
Registered: 2019-07-08
Posts: 15

Re: [SOLVED] Sync script at the end of the session

damo wrote:

Helium uses a python bl-exit script, so I reckon you would edit the relevant line in def main()

action = "myscript.sh;poweroff"

and where should I place the script?

Offline

#4 2020-01-03 00:28:18

damo
....moderator....
Registered: 2015-08-20
Posts: 5,403

Re: [SOLVED] Sync script at the end of the session

Uooops wrote:

...
and where should I place the script?

Same as any other script - in your $PATH: eg $HOME/bin, /usr/local/bin etc.

I suggest you run bl-exit in the terminal to test things out.


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#5 2020-01-03 03:18:15

Uooops
Member
Registered: 2019-07-08
Posts: 15

Re: [SOLVED] Sync script at the end of the session

It doesn't work.

I'm editing /usr/bin/bl-exit as you explained before.

Maybe it is the wrong file?

Maybe I have to do any other change in the file?

Last edited by Uooops (2020-01-03 03:20:37)

Offline

#6 2020-01-03 03:56:53

damo
....moderator....
Registered: 2015-08-20
Posts: 5,403

Re: [SOLVED] Sync script at the end of the session

Uooops wrote:

It doesn't work.
...

Not a helpful answer.

Please say exactly what you did, and what the terminal output was.

EDIT: seems like there is an array error doing things the way I suggested. It worked in the old Crunchbang  exit script though! It is probably best to use a systemd shutdown script instead.

Last edited by damo (2020-01-03 04:05:20)


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#7 2020-01-03 04:34:15

damo
....moderator....
Registered: 2015-08-20
Posts: 5,403

Re: [SOLVED] Sync script at the end of the session

This works: get the Lithium bl-exit script from https://github.com/BunsenLabs/bunsen-ex … in/bl-exit, and put it in ~/bin.

Change the logoutctl() function to include "your-script.sh" (obviously change it to the name of your script!)

logoutctl(){
    if [[ ! -z $YAD_PID ]]; then
        kill -SIGUSR1 $YAD_PID
    fi
    case $1 in
        cancel )
            echo -e "\ncancelled"
            exit 0 ;;
        lock-session )
            echo -e "\n$1"
            [[ ! -z "$LOCK_SCREEN_COMMAND" ]] && $LOCK_SCREEN_COMMAND || loginctl $1 $XDG_SESSION_ID
            exit $? ;;
        terminate-session )
            echo  -e "\n$1"
            loginctl $1 $XDG_SESSION_ID
            exit $? ;;
        suspend | hibernate | hybrid-sleep | suspend-then-hibernate | reboot )
            echo -e "\n$1"
            # The systemd or elogind compatibility magic.   #
            [[ $(command -v systemctl) ]] && systemctl "$1" || loginctl "$1"
            exit $? ;;
        poweroff )
            echo -e "\n$1"
            # The systemd or elogind compatibility magic.   #
            [[ $(command -v systemctl) ]] && your-script.sh;systemctl "$1" || loginctl "$1"
            exit $? ;;
    esac
}

Use it at your own risk!

(And it would still be best practice to use systemd)


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#8 2020-01-03 11:03:54

ohnonot
...again
Registered: 2015-09-29
Posts: 4,216
Website

Re: [SOLVED] Sync script at the end of the session

Personally I wouldn't recommend editing what is in /usr/bin, but first copy it to $HOME/bin and edit the copy.

Uooops wrote:

I'm trying to sync some files between two computers at the beginnig and at the end of session. I've get the first thing done but I don't know how to do the last.

I wonder how you are doing all this in the first place?

I've read that setting the script in systemd could be an option but I would like to know if there are more possibilities.

Depends on the answer to my question.

Offline

#9 2020-01-03 11:30:56

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

Re: [SOLVED] Sync script at the end of the session

Why not set up continuous synk?

Syncthing, is one good tool for that. Its crossplatform, for Windows, Linux, Mac and android.
It is in Debian repo, but is quite behind. In oldstable its only v. 0.14.18. In Syncthings Debian repo, stable v. is 1.3.2. That works both on Stretch and Buster (oldstable/stable).

It takes about 90 MiB RAM.

Syncthings homepage: https://syncthing.net


// Regards rbh

Offline

#10 2020-01-03 12:16:40

Uooops
Member
Registered: 2019-07-08
Posts: 15

Re: [SOLVED] Sync script at the end of the session

Hello

damo wrote:
Uooops wrote:

It doesn't work.
...

Not a helpful answer.

Please say exactly what you did, and what the terminal output was.

...

sorry

What I did was:

1. write an script for sync and give permission for execute
2. place the name of the script in bl-exit def main as

action = "end-script.sh;poweroff"

3. when I run bl-exit I choose poweroff and it only shutdowns the system, skipping end-script.sh

damo wrote:

This works: get the Lithium bl-exit script from https://github.com/BunsenLabs/bunsen-ex … in/bl-exit, and put it in ~/bin.

Change the logoutctl() function to include "your-script.sh" (obviously change it to the name of your script!)...

I've made as you say and it is the same problem, it still skips end-script.sh when turnoff

I'm doing something wrong, maybe something with the script

ohnonot: Im using rclone to sync computers. The script for the beginning is placed in autostar

rbh: I tought it was better just syncing at the beginning and end, but maybe I should try it

Thank you all for your help

Edit: I've edit /usr/bin/bl-exit with:

action = "end-script"

Removing poweroff action and it still end the session.

Do I have to run any command same as when editing GRUB?

Last edited by Uooops (2020-01-03 13:03:32)

Offline

#11 2020-01-03 13:59:25

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

Re: [SOLVED] Sync script at the end of the session

Uooops wrote:

What I did was:

2. place the name of the script in bl-exit def main as

action = "end-script.sh;poweroff"

Did you write "end-script.sh", or "end-script", as you wrote later?

rbh: I tought it was better just syncing at the beginning and end, but maybe I should try it

Well, it depends. If memory and cpu is very low it is better not to sync during work. If PC better than 1 GHz, 1GB, I think, better with continous sync.

Last edited by rbh (2020-01-03 13:59:52)


// Regards rbh

Offline

#12 2020-01-03 14:04:40

Uooops
Member
Registered: 2019-07-08
Posts: 15

Re: [SOLVED] Sync script at the end of the session

I wrote end-script.sh

I had a mistake writing the post

Offline

#13 2020-01-03 18:20:21

Uooops
Member
Registered: 2019-07-08
Posts: 15

Re: [SOLVED] Sync script at the end of the session

I got it!!

I added this lines to the code

Import subprocess

subprocess.call("end-script.sh")

Now it syncs before bl-exit menu starts

Thank you very much for your suggestions.

Offline

Board footer

Powered by FluxBB