Domanda

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!

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top