I found a solution:
I simply needed to use "killall -u" instead of the "skill -KILL -u". :)
As indicated here: http://www.cyberciti.biz/tips/howto-linux-kill-and-logout-users.html , the command "skill" seems to be obsolete and others like pkill and killall should be used instead. pkill didn't do what I want, but killall did. :)
So here's the full solution:
1) Create a script /etc/init.d/killusers containing the following:
#!/bin/bash
#
# chkconfig: 35 90 12
# description: Foo server
#
# Get function from functions library
#. /etc/init.d/functions
. /lib/lsb/init-functions
# Start the service FOO
start() {
#initlog -c "echo -n Starting FOO server: "
#who | cut -d " " -f1 | uniq | xargs killall -u
#who | cut -d " " -f1 | uniq | xargs skill -KILL -u
#success $"FOO server startup"
echo "Do nothing"
}
# Restart the service FOO
stop() {
#initlog -c "echo -n Stopping FOO server: "
who | cut -d " " -f1 | uniq | xargs killall -u
#who | cut -d " " -f1 | uniq | xargs skill -KILL -u
#who | cut -d " " -f1 | uniq | xargs pkill -STOP -u
}
### main logic ###
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status FOO
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
( script based on http://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html )
2) Make it executable:
sudo chmod +x /etc/init.d/killusers
3) Add it to the shutdown scripts:
sudo update-rc.d killusers defaults
Note 1:
I think runlevel 6 should be enough, but I went for defaults just to be sure. The script could probably also only contain the kill command if it is just run during shutdown.
Note 2:
To save the bash history immediately, you can use (thanks to HampusLi):
history -a
So you could also just run:
history -a && sudo reboot
But I wanted it to work for any user and without having to create an alias, script or similar.