Execute at login
Helmut Schneider
jumper99 at gmx.de
Tue Sep 27 20:04:10 UTC 2011
Polytropon wrote:
> On Mon, 26 Sep 2011 20:41:43 +0000 (UTC), Helmut Schneider wrote:
> > Hi,
> >
> > which options do I have to execute at login?
> >
> > I would like to implement something like update-motd [1] without
> > actually modifying /etc/motd. The code snippet is
> >
> > if [ -d /etc/motd.d ]; then
> > for FILE in /etc/motd.d/*; do
> > [ -x ${FILE} ] && ${FILE}
> > done
> > fi
> >
> > It should be executed for all users but only at login (regardless if
> > she/he logs in via console or ssh). It also should be independent of
> > the login shell. Therefore neither /etc/profile nor ~/.profile nor
> > ~/.login seem suitable.
> >
> > Where can I put that code? The content of /etc/motd.d/ can change
> > anytime.
>
> I'm not sure if this works, but maybe something like this
> can be an idea to create a comparable solution:
>
> You can (ab)use the "login shell" property of /etc/passwd
> to give all users a login shell that is the above script
> which then executes the real login shell for the users
> (I assume this will be either bash or csh).
>
> See "man 5 passwd" for details.
>
> However, this approach can cause trouble in combination with
> chsh. It also doesn't seem to be limited to interactive logins,
> so there should be some test in the script to check if the
> current shell is in dialog mode
>
> For csh, this can be done by
>
> if ($?prompt) then
> ... interactive shell stuff ...
> endif
>
> But again, this does not apply to different login shells.
>
> An idea to compensate this could be to employ login.conf
> instead, per the "shell" environmental setting. This seems
> to override the shell defined in /etc/passwd (which can be
> subject to a chsh call).
>
> See "man 5 login.conf" for details.
>
> The script mentioned above could therefore include the
> following steps:
>
> 1. determinate kind of shell:
> in case of interactive shell, continue
>
> 2. check for motd.d functionality:
> if /etc/motd.d/ exists and has executable files
> in it, execute them (basically your script concept)
>
> 3. determine user's dialog shell
> read /etc/passwd and start the user's dialog shell
> by exec <shellname>
>
> You can write this in any (shell) script language you want.
> I would suggest plain #!/bin/sh syntax.
Thanks for that, but I prefer a "straighter" way. :) It seems someone
had the same idea before:
<http://cvsup6.freebsd.org/pub/FreeBSD/development/FreeBSD-CVS/src/contrib/libpam/modules/pam_motd/Attic/>
Anyone knows why it was discontinued?
More information about the freebsd-questions
mailing list