Edit /etc/profile so that all users are greeted upon login.
For the root account, set the prompt to something like "Danger!! root is doing stuff in \w", preferably in a bright color such as red or pink or in reverse video mode.
/etc/profile is a shell script, so if you want to echo something, echo something . You can tell different users apart with the USER variable, if set. If it's not set, don't bother doing anything since you might be injecting 'Hi everybody!' into somebody's cron job or something equally pointless.
Assuming this is unix.
The convention is to put the message in the file /etc/motd (Message of the Day).
Check your /etc/profile file because most of the manufacturer supplied versions of /etc/profile look for the Message of the Day file. Don't forget to undo the change when you have finished.
Change the root prompt at your own risk. Remember that whoever logs in as root may not be using the same type of terminal as you!
No, it is not my homework. It is a bash practice problem from Bash Guide for Beginners
I am using Linux fedora 14. I just want to improve myself.
Thanks.
---------- Post updated at 11:43 AM ---------- Previous update was at 11:35 AM ----------
How to modify profile?
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT good idea to change this file unless you know what you
# are doing. Much better way is to create custom.sh shell script in
# /etc/profile.d/ to make custom changes to environment. This will
# prevent need for merging in future updates.
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
if [ -x /usr/bin/id ]; then
if [ -z "$EUID" ]; then
# ksh workaround
EUID=`id -u`
UID=`id -ru`
fi
USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi
# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
else
pathmunge /usr/local/sbin after
pathmunge /usr/sbin after
pathmunge /sbin after
fi
HOSTNAME=`/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
export HISTCONTROL=ignoreboth
else
export HISTCONTROL=ignoredups
fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. $i
else
. $i >/dev/null 2>&1
fi
fi
done
unset i
unset pathmunge
With a text editor like nano or vim. You'll need to su - into root to get sufficient privileges to edit it. But, reading this file:
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT good idea to change this file unless you know what you
# are doing. Much better way is to create custom.sh shell script in
# /etc/profile.d/ to make custom changes to environment. This will
# prevent need for merging in future updates.
...and this code:
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. $i
else
. $i >/dev/null 2>&1
fi
fi
done
...would suggest that you create a file under /etc/profile.d/ instead.
Try creating a /etc/profile.d/99-hello.sh file with this: