Login and auto executes

Polytropon freebsd at edvax.de
Sun Jul 6 09:55:00 UTC 2014

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:

              The bash executable
              The systemwide initialization file, executed for login shells
              The personal initialization file, executed for login shells
              The individual per-interactive-shell startup file
              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.

Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

More information about the freebsd-questions mailing list