Pergunta

Simple question -- I want to add something to the system .bashrc (in a RHEL6 environment, if that makes a difference) that will then get added to every user's .bashrc on account creation, but I only want it to run the first time a user logs in and never again. Is it a completely terrible idea to just do some sed piping to make it so that .bashrc looks like the below?

  1. run command
  2. erase lines 1 and 2 and overwrite itself.

If this is way off the wall, would be curious to hear alternatives. Thanks!

Foi útil?

Solução

Rather than trying to modify code, the standard practice is to create a file to flag whether something's run:

if [[ ! -f ~/.first_run ]]
then
  echo "Welcome to $HOSTNAME!"
  touch ~/.first_run
fi

This approach is simpler and allows you to e.g. symlink all default .bashrc files to the same system-wide standard and more robustly determine the user's state in other tools.

Outras dicas

Debian-based distributions have the sysnews package that allows creating messages that are displayed only once to the users. It works the way @thatotherguy describes in his answer. I am not sure an equivalent RPM for RH-based distributions exists so you might need to compile it from sources.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top