linux - Idle timeout Bourne-style shell

07
2014-07
  • Ram

    Is there any way to timeout idle users in Bourne-style shell (/bin/sh).

    man sh does not talk about it.

    http://www.freebsd.org/cgi/man.cgi?sh

    TIMEOUT or TMOUT shell env variables in /etc/profile work fine in bash and ksh.

    C-Shell has /etc/csh.logout set autologout option.

    http://www.freebsd.org/cgi/man.cgi?csh

    I don't find any similar option in case of sh (/bin/sh).

    Thanks.

  • Answers
    Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

    Related Question

    unix - shell dotfiles and *rcs: what's a sane setup?
  • kch

    A bash user will eventually end up with .bashrc, .bash_profile, .profile, and maybe some more.

    Now, each file gets loaded unders particular situations, and it all leads to confusion and frustration. I don't care about what shell is a login shell and neither should you.

    I just want to make sure the same thing is loaded for every shell thing that happens.

    So, what's the sane way to set them up?

    I'd wager non-bash-specific things go into .profile, and some file sources the others, etc. What exactly would in put in each to achieve an identical environment for every shell?

    Note: I'm not asking what you particularly enjoy putting in your rc files, like aliases and functions and so on. Just how you lay them out so as not to have things randomly spliced amongst them.


  • Related Answers
  • Jonathan Leffler

    I just want to make sure the same thing is loaded for every shell thing that happens.

    If you really want that, put everything in ~/.profile and add a source ~/.profile at the end of your ~/.bashrc. If this is desirable is a different question. To source ~/.profile in ~/.bashrc is a very common setup anyway.

    +------------+-----------------+--------------------+
    |            | login shells    | interactive shells |
    +------------+-----------------+--------------------|
    | all        | /etc/profile    |                    |
    | bourneish  | ----------------+--------------------|
    | shells     | ~/.profile      |                    |
    +------------+-----------------+--------------------|
    | just       | ~/.bash-profile | /etc/bash.bashrc   |
    |            | -------------------------------------|
    | bash       | ~/.bash-login   | ~/.bashrc          |
    +------------+-----------------+--------------------+
    

    C shell and shells derived use a different set of files (.login, .cshrc, ..).

    What exactly would in put in each to achieve an identical environment for every shell?

    If you mean environment in the sense of environment variables, just set all of them in ~/.profile and you are OK. If you mean environment in a broader sense, it depends.

    The issue here is that it is not desirable to have the very same environment for interactive and login shells. An example is aliases: Maybe you want aliases in your interactive shell, but very likely they will make your scripts do weird things. So you don't want your aliases in non-interactive shells => put them in ~./bashrc.