Date: Tue, 27 Sep 2011 20:03:53 +0000 (UTC) From: "Helmut Schneider" <jumper99@gmx.de> To: freebsd-questions@freebsd.org Subject: Re: Execute at login Message-ID: <xn0hjm9h697jbd003@news.gmane.org> References: <xn0hjkvuc1rcr4o000@news.gmane.org> <20110927202731.9df2bc28.freebsd@edvax.de>
next in thread | previous in thread | raw e-mail | index | archive | help
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?
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xn0hjm9h697jbd003>