I have written (or at least I'm trying) a script that will close a session of screen when the system is going down (rc0) or rebooting (rc6).
I have placed this script in /etc/init.d/ and chmoded it u+x.
I have also made symbolic links to rc0 and rc06 which I added with the tool sysv-rc-conf
# Script name = irctor
case $1 in
su --login -c 'screen -S irctor -X quit' erikw
# test if the scripts runs
echo 'It do works' > /home/erikw/works.txt
It looks OK I think. If I have understood everything right links in runlevel 0 or 6 will be called with the parameter 'stop' which will in this case stop the session of screen named irctor.
erikw@compton:~$ cd /etc/rc0.d/
erikw@compton:/etc/rc0.d$ ls -l *irctor*
lrwxrwxrwx 1 root root 16 2008-07-02 14:26 S74irctor -> ../init.d/irctor
erikw@compton:/etc/rc0.d$ cd /etc/rc6.d/
erikw@compton:/etc/rc6.d$ ls -l *irctor*
lrwxrwxrwx 1 root root 16 2008-07-02 14:35 S74irctor -> ../init.d/irctor
But the thing is that screen-sessions are user-bound so root can't (at least I think) access or stop screen sessions that I (erikw) have started. To solve this you should probably use the command su like I did in the /etc/init.d/irctor script but the problem with that is that su seems to required a password input to continue executing to command.
My question is: how do i get around the enter-password-thing?
Any help is appreciated! ( I have red this manual or what is it)