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

Run script at shutdown

Tags: None
(comma "," separated)
doahh
Registered Member
Posts
7
Karma
0
OS

Run script at shutdown

Sun Feb 13, 2011 12:30 pm
I want to run a script when the user clicks the shutdown button in KDE4. If I put the entry into the ~/.kde/shutdown folder then it only runs AFTER the shutdown process has started, and KDE has closed. I would like to run the script before KDE exists, so that I can abort the KDE exit from the script. Adding it to the:

Code: Select all
System setting > Startup and Shutdown


gives me the same problem. My script simply calls:

Code: Select all
kdesudo 'shutdown -c'


to abort shutdown if necessary.

Does anyone know how to abort the shutdown before KDE exits?
User avatar
google01103
Manager
Posts
6668
Karma
25

Re: Run script at shutdown

Sun Feb 13, 2011 2:37 pm
couldn't you supersede the shutdown command called from kmenu with a script you wrote? if this script was early in the $PATH searched than it would be executed, of course then all calls to the "shutdown" (assuming it's whats being called) command would be also superseded and you would need to handle all possible variations.

caveat - not being a dev I could be totally wrong about this and it could just be dumb


OpenSuse Leap 42.1 x64, Plasma 5.x

doahh
Registered Member
Posts
7
Karma
0
OS

Re: Run script at shutdown

Sun Feb 13, 2011 4:47 pm
Thanks for the reply, but I am not sure how to do that. I have been using Linux for a while, but I have never had to modify it's internal code before. I don't mind doing so though.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: Run script at shutdown

Mon Feb 14, 2011 12:28 am
Note that KDE uses communication with KDM/ConsoleKit to enact the shutdown of the system, rather than directly invoking any shutdown commands itself.

What is the exact purpose of this script?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
doahh
Registered Member
Posts
7
Karma
0
OS

Re: Run script at shutdown

Wed Feb 16, 2011 5:38 pm
This is the script, the purpose of which is to offer an abort option during the shutdown process if the backup-manager process is running, and the user has pressed the shutdown button in the KDE menu:

Code: Select all
#!/bin/sh

SERVICE='backup-manager'
 
#
if ! ps -C $SERVICE > /dev/null
then
   # Do nothing as we are not in the middle of a backup
    echo "$SERVICE is NOT running"
else
    zenity --question --title "Backup-manager is running" --text "Backup-manager is running. If you continue to shutdown then you may loose backup data. \n\nAre you shre you want to shutdown";

   if [ $? = 0 ]; then
     echo "Continuing with shutdown"
   else
     echo ""
     echo "Attempting to abort shutdown"
     kdesudo 'shutdown -c'
   fi
fi
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: Run script at shutdown

Wed Feb 16, 2011 11:12 pm
I would suggest using the X Session Management Protocol (XSMP) to communicate with the KDE Session Manager. Applications can request that the session not exit if needed as part of this protocol.

See http://www.xfree86.org/current/xsmp.pdf and http://en.wikipedia.org/wiki/X_session_manager


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]