I want to execute script before I shutdown my machine that writes date to a file (so I do know what time I finish working).
How to do it?
What you are looking for is an init script: take a look at the Upstart How to.
You basically need to place your script in
The name of the link determines the order and when (start or shutdown) it's executed.
Links beginning with
You could also execute a script when X ends or gnome logs you out, but I think init scripts are the cleanest solutions.
If going with the first option Debian based systems like Ubuntu provide the command line tool