From owner-freebsd-questions@FreeBSD.ORG Tue Sep 27 18:27:32 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D1EB8106564A for ; Tue, 27 Sep 2011 18:27:32 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de (mx01.qsc.de [213.148.129.14]) by mx1.freebsd.org (Postfix) with ESMTP id 9687F8FC1B for ; Tue, 27 Sep 2011 18:27:32 +0000 (UTC) Received: from r56.edvax.de (port-92-195-14-151.dynamic.qsc.de [92.195.14.151]) by mx01.qsc.de (Postfix) with ESMTP id ACDEC3E278; Tue, 27 Sep 2011 20:27:31 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id p8RIRV6M005775; Tue, 27 Sep 2011 20:27:31 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Tue, 27 Sep 2011 20:27:31 +0200 From: Polytropon To: "Helmut Schneider" Message-Id: <20110927202731.9df2bc28.freebsd@edvax.de> In-Reply-To: References: Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: freebsd-questions@freebsd.org Subject: Re: Execute at login X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Sep 2011 18:27:32 -0000 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 You can write this in _any_ (shell) script language you want. I would suggest plain #!/bin/sh syntax. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...