.\" $NetBSD: ttyaction.5,v 1.11 2021/03/22 00:09:06 wiz Exp $
.\"
.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Gordon W. Ross.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd August 24, 1996
.Dt TTYACTION 5
.Os
.Sh NAME
.Nm ttyaction
.Nd ttyaction file format
.Sh DESCRIPTION
The
.Nm ttyaction
file specifies site-specific commands to run
when a login session begins and ends.
The
.Nm ttyaction
file contains a list of newline separated records, where
each record has the following three fields:
.Bl -tag -width username
.It ttyname
Name of the tty line(s) on which this line should apply.
The name is relative to the
.Pa /dev
directory, similar to how such devices are named in the
.Pa /etc/ttys
file.
.It action
Name of the action for which this line should apply.
The action names currently defined are "login", "getty",
"telnetd" and "rlogind"
which indicate which program is processing this file.
(Note that "login" begins a login session, while the other
three are run after a login session ends.)
.It command
What command to run if this record matches.
.El
.Pp
The first two fields are delimited with blanks or tabs,
and the command field is all text to the end of the line.
Either or both of first two fields may contain wildcard
match patterns as implemented by the
.Xr fnmatch 3
library function.
.Pp
All command strings are executed by passing them to
.Pa /bin/sh \-c
running as "root," with an environment containing:
.Bd -literal -offset indent
TTY=ttyname
ACT=action
USER=username
PATH=_PATH_STDPATH
.Ed
.Pp
These variables may be used directly in the shell command
part of the record for simple tasks such as changing the
ownership of related devices.
For example:
.Bd -literal -offset indent
console * chown ${USER}:tty /dev/mouse
.Ed
.Pp
will
.Fa chown
the mouse appropriately when the console owner changes.
.Sh EXAMPLES
Here are some more example records:
.Bd -literal -offset indent
tty0 login /somewhere/tty_setup ${TTY}
tty0 getty /somewhere/tty_clean ${TTY}
* * /somewhere/ttyfrob ${TTY} ${ACT}
.Ed
.Sh SEE ALSO
.Xr fnmatch 3 ,
.Xr ttyaction 3
.Sh HISTORY
Support for the
.Pa /etc/ttyaction
file first appeared in
.Nx 1.3 .
The ideas for the
.Pa /etc/ttyaction
file were inspired by the
.Pa /etc/fbtab
file under SunOS.