From owner-freebsd-questions@FreeBSD.ORG Sun Jul 6 09:55:00 2014 Return-Path: Delivered-To: freebsd-questions@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A13B6774 for ; Sun, 6 Jul 2014 09:55:00 +0000 (UTC) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6500F22CF for ; Sun, 6 Jul 2014 09:55:00 +0000 (UTC) Received: from r56.edvax.de (port-92-195-69-249.dynamic.qsc.de [92.195.69.249]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx02.qsc.de (Postfix) with ESMTPS id C30D524C5D; Sun, 6 Jul 2014 11:54:56 +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 s669subE003647; Sun, 6 Jul 2014 11:54:56 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Sun, 6 Jul 2014 11:54:56 +0200 From: Polytropon To: Jos Chrispijn Subject: Re: Login and auto executes Message-Id: <20140706115456.537c5fba.freebsd@edvax.de> In-Reply-To: <53B9163E.3040406@webrz.net> References: <53B9163E.3040406@webrz.net> Reply-To: Polytropon 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" X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Jul 2014 09:55:00 -0000 On Sun, 06 Jul 2014 11:26:22 +0200, Jos Chrispijn wrote: > (1) I have this regular user U1. After I log in to that user account, I > would like to start a script that does some other commandlines. > For this purpose I created .bash_profile and .bashrc in the U1 user > folder, containing a simple test command like 'ls': Directory. :-) > .bashrc > ls -alt > > In the .profile of the U1 user I put at the last line: > [ $BASH ] && [ -f ~/.bashrc ] && . ~/.bashrc This looks complicated. In my opinion, bash should do this automatically. According to "man bash", FILES section: /usr/local/bin/bash The bash executable /etc/profile The systemwide initialization file, executed for login shells ~/.bash_profile The personal initialization file, executed for login shells ~/.bashrc The individual per-interactive-shell startup file ~/.bash_logout The individual login shell cleanup file, executed when a login shell exits So it should be sufficient to place commands to be automatically executed at login time _only_ in ~/.bash_profile. > (2) I also tried putting the extra commands in the U1 .profile: > > --- cut --- > > echo '-- UPTIME --' > uptime > echo '' > echo '-- Who is ONLINE --' > who > > --- cut --- > > but this also is not executed. The file ~/.profile is reserved for /bin/sh. From "man sh": A login shell first reads commands from the files /etc/profile and then .profile in a user's home directory, if they exist. [...] Therefore, a user should place commands that are to be executed only at login time in the .profile file, and commands that are executed for every shell inside the ENV file. Note that using sh as an interactive shell doesn't look like a pleasant experience. :-) > What do I overlook and/or is there an > easier way of execting some after-login commands? Just use the correct file. Maybe call the commands explicitely (with full path) or define $PATH if needed. And finally make sure bash is invoked as the login shell, not "accidentally" csh. :-) In case of the C shell, use ~/.login to place commands to be executed after login, for your user, and ~/.cshrc for settings that should be applied to all interactive C shells. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...