[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: logout script



On Wed, Nov 24, 2004 at 04:57:15AM -0700, Thomas Beresford wrote:
> Is there a way to create a script to run some commands whenever I logout the
> machine? Is so,how?

Do you mean to run some commands during shutdown?

You can put a numbered script in /etc/rc0.d (or symlink to one) and it will get
run at shutdown.  Or you can change one of the existing scripts, for example I
changed the "halt" script recently on a special-purpose box so that it makes a
sound when the machine has been halted (so a blind person to know when it's
safe to turn it off).  Generally it's a better idea to make a separate script
so that when you upgrade you don't have to merge your changes with Debian's
ones.

here's an simple example, that rings the bell some time before system halt:

  cd /etc/rc0.d
  echo "echo $'\a'" >S80bell
  chmod +x S80bell


normally people tend to put the scripts in /etc/init.d
and symlink to them from /etc/rc*.d :

  cd /etc/init.d
  echo "echo $'\a'" >bell
  chmod +x bell
  cd /etc/rc0.d
  ln -s ../init.d/bell S80bell

I haven't tested this, hopefully it's right!


BTW - is $'\a' a bashism?  if so, what's the sh / POSIX way to do it?
I know I've seen things like:
	echo "foo\n"

in some shells, but bash apparently doesn't like this.


Sam



Reply to: