systemd-inhibit doesnt work with cinnamon gui shutdown button

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
wullewu

systemd-inhibit doesnt work with cinnamon gui shutdown button

Post by wullewu »

Hi,
I have a backup-script for my Linux Mint machine. I wanted to block shutdown, sleep or logout commands until the script is running.

systemd-inhibit --what=shutdown:sleep:idle:handle-power-key:handle-suspend-key:handle-hibernate-key:handle-lid-switch tar -czf /media/fabian/hdd_extern/backup_fabian/home_$datum.tar.gz /home/fabian/*

So far so good. It works when i try to shutdown the machine via commandline, but when I press the shutdown button in the cinnamon gui the user logs off an the process gets terminated.

Has anyone an idea how to fix this? Thanks for your answers :-)
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
g3rb

Re: systemd-inhibit doesnt work with cinnamon gui shutdown button

Post by g3rb »

Same for me !
User avatar
Termy
Level 12
Level 12
Posts: 4254
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: systemd-inhibit doesnt work with cinnamon gui shutdown button

Post by Termy »

Use nohup before your command; it keeps the process alive, if the HUP signal is sent to it. Might help. You can also tell your script what to do if it detects the HUP (or other) signal, using the trap builtin -- see help trap. Example usage of the trap command:

Code: Select all

#!/bin/bash

trap 'printf "\nSignal HUP (1) or INT (2) detected.\n"' HUP INT

for INT in {9..1}; {
        printf "\rSleeping for %d second(s)..." "$INT"
        /bin/sleep 1s
}

printf "\nThe script executed without being hung up.\n"
Send the HUP or INT signal during the 9-second countdown (with kill or ^C) to see it work.
I'm also Terminalforlife on GitHub.
Locked

Return to “Scripts & Bash”