This forum has been archived. All content is frozen. Please use KDE Discuss instead.

is there a way how I can run a script on logout/shutdown?

Tags: None
(comma "," separated)
somebody
Registered Member
Posts
15
Karma
0
Hi,

is there a way how I can run a shell scipt on logout/shutdown/reboot?

I tried the $HOME/.config/plasma-workspace/shutdown folder, but it doesn't seem to do anything. Is there some other way?

In case the shutdown directory should work, here is what I've tried:
1. Copy the script to the directory (via konsole)
2. symlink the script to that directory (via konsole)
3. Add 'logout' script via 'System Settings/Autostart'. I tried both options (symlink or copy) and selected 'Logout' in the 'Run On' column

The script is named nas_umount.sh and it's executable and readable by user, group and others. Currently it only contains:
#!/usr/bin/env bash
echo "executed2" >> /tmp/shutdown
date >> /tmp/shutdown

No /tmp/shutdown is created (unless I call the script manuall in konsole)
Thanks
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS
Hi!

You can run a script on logout via the "Startup & Shutdown - Autostart" in systemsettings5, but depending on how your connections work, you cannot place everything in a script. How is your NAS mounted? How is your network connection handled? If you're using e.g. NetworkManager, you can trigger scripts on events with Dispatcher-scripts.
somebody
Registered Member
Posts
15
Karma
0
Can you please be more precise how I can do it with systemsettings5?
I don't think it's possible - as I said, I've tried to add both - link and copy to the System Settings/Startup and Shutdown/Autostart and I set Run On as Logout. I'm not sure what that settings meant to be for, but it doesn't executes the scripts after logout (altough according to the documentation it should, so i'm not sure, definitelly it sounds like it's the right place to use).
I have the NAS connected via WiFi as CIFS. Actually, that's the real problem I'm trying to solve here. Can KDE somehow disconnect the mounted network partitions on logout?
The problem is that the WiFi is password protected (WPA2) so it really connects only after I log-in with my KDE account. After logout, the connection is lost and during shutdown it can not correctly unmount and needs to wait for timeout for each directory mounted this way.
I've tried to create NetworkManager dispatcher script, but again - without any luck. I have such script to mount the NAS, when the connection is estabilished, and it works fine. But I can't make it work just BEFORE the connection is dropped..
Sounds like I should use some pre-down event, but unfortunatelly this comment is in my /etc/NetworkManager/dispatcher.d/01-ifupdown
Code: Select all
# pre-up/pre-down not implemented. See
# https://bugzilla.gnome.org/show_bug.cgi?id=387832
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS
I do not really have an idea of Samba-mounting as I'm using FUSE/sshfs to mount via SSH-keys and I do not use NetworkManager either (but remembered the dispatcher.d-method). If you are mounting via KIO (knetattach) plasma should be able to unmount it flawlessly. If you're mounting via /etc/fstab, it is up to the root account to take care of the unmount - and you should add _netdev to the options there. A logout script with user permissions won't help here, thats why I was asking.

Which OS do you use? The bugreport you referred to seems to be fixed since 2014 :)
somebody
Registered Member
Posts
15
Karma
0
I have the _netdev options in /etc/fstab. But it's not able to mount, since the connection to WiFi is only possible after I login to my KDE account (since it remembers the password). But the dispatcher script is able to mount it.
I'm using Kubuntu 20.04, freshly installed (ok, not freshly, it's like one month ago, but no upgrade from previous version or anything similar).
I didn't know about the knetattach, I will try that. I have it like this because I was used to have ethernet connection and in that case everything worked fine.
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS
As mentioned before, you can use /etc/fstab entry, but then you have to manage the unmount yourself. The dispatcher seems to work since Ubuntu 18.04. Create a file /etc/NetworkManager/dispatcher.d/pre-down.d/myNasUnmount
Code: Select all
case "$2" in
   pre-down)
              umount -a -t cifs #or what command you need there
              ;;
esac
and chmod it with 700 (execution rights for owner, nothing for groups and others)

But of course, you can give the KIO-system a chance :)
somebody
Registered Member
Posts
15
Karma
0
Nice, this seems to be working.
thanks :)


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], q.ignora, watchstar