Create your shell script in /etc/init.d-- let's suppose for purposes of this example you're going to call the script "screenshutdown". Then you have to make links to the script in the various /etc/rc?.d directories:
The link to the script in the approrpriate /etc/rc?.d directory is what causes it to be executed when the system shuts down.
for d in /etc/rc?.d; do
ln -s /etc/init.d/screenshutdown $d/S99screenshutdown
You might find this thread helpful for explaining the role of these various directories in the system boot process: