Operating System - HP-UX
1825934 Members
2648 Online
109689 Solutions
New Discussion

user profiles and shell environments

 
SOLVED
Go to solution
Mladen Despic
Honored Contributor

user profiles and shell environments

What are some of the ways to customize the (posix) shell environment in /etc/profile, ~/.profile, ~/.kshrc, ... ?

As a small example of what I'd like to see, the HP manual "Shells: User's Guide", Chapter 23, gives the following interesting code:

EXPORT ENV='${FILE[(_$-=1)+(_=0)-(_$-!=_${-%%*i*})]}'
export FILE=$HOME/.envfile

which cuases the $HOME/.kshrc to be executed, unless you are in an interactive shell.

If you have other examples that you've found useful for your environment, even if it's just setting up your TERM variable, please share them here. Thanks,

Mladen
11 REPLIES 11
John Dvorchak
Honored Contributor
Solution

Re: user profiles and shell environments

These are in /etc/profile for all users -
How about checking for mail:

# Notify if there is mail

if [ -f /usr/bin/mail ]
then
if mail -e
then echo "You have mail."
fi
fi


or for a really nice prompt with system name, working directory and who you are logged on as:

export SYSNAME=`uname -n`
export PS1='${SYSNAME}:[ ${PWD} ]
${LOGNAME}> '



Good luck
If it has wheels or a skirt, you can't afford it.
Todd McDaniel_1
Honored Contributor

Re: user profiles and shell environments

I use these options for anyone who logs in as root... creates history and .sh_user for each root user based upon their username...


# sets .sh_hist file to id of user

if [ "`tty`" = "/dev/console" ]
then
REAL=console
else
REAL=`logname`
fi

HISTFILE=$HOME/.sh_$REAL
export HISTFILE
HISTSIZE=1000; export HISTSIZE


I also have a few aliases...

# list of my aliases
alias dir='ls -la'
alias lt='ls -lt'
alias lrt='ls -lrt'
alias pp='ps -aef|grep'
alias lsfg='lsf |grep '\/''
alias tops='top -h -s 1'
alias ls='ls -l'
alias bpps='/opt/openv/netbackup/bin/bpps -a'

##My users' prompt is as follows:

export PS1="`hostname`:/\${PWD#*}> "
Unix, the other white meat.
G. Vrijhoeven
Honored Contributor

Re: user profiles and shell environments

Hi,

How abount a little ascii ART before you startup:

http://www.chris.com/ascii/

http://www.ascii-art.de/

http://www.arkworld.com/ascii/

Gideon
G. Vrijhoeven
Honored Contributor

Re: user profiles and shell environments

Hi,

How about a little ascii ART before you startup:

http://www.chris.com/ascii/

http://www.ascii-art.de/

http://www.arkworld.com/ascii/

Gideon
Sridhar Bhaskarla
Honored Contributor

Re: user profiles and shell environments

Hi Mladen,

One of the things I did is to manipulate /etc/profile (and /etc/csh.login) not to allow certain users to login to the box. Write a bit of code that reads a file and compares it again $LOGNAME and exits if it matches.

Other thing is to set a "readonly" TMOUT value like export TMOUT=20;readonly TMOUT

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Todd McDaniel_1
Honored Contributor

Re: user profiles and shell environments

Actually, I have a TMOUT variable I use...

if [ "$TMOUT" != 7200 ]
then
if [ $LOGNAME = "" ]
then
TMOUT=999999; export TMOUT; readonly TMOUT
else
TMOUT=7200; readonly TMOUT; export TMOUT
fi
fi
Unix, the other white meat.
Geoff Wild
Honored Contributor

Re: user profiles and shell environments

We have multiple admins with root access - a neat thing we do is setup a separate .sh_history for each of us:

# Setup logging
HISTFILE=${HOME}/.sh_history_`who am i|awk '{ print $1 }'`
date >>$HISTFILE
export HISTFILE
HISTSIZE=500
export HISTSIZE

echo "WARNING: YOU ARE SUPERUSER !!\n"

HOST=`uname -n`
PS1="\$HOST:\$LOGNAME:\$PWD # ";export PS1
stty erase ^H
set -o vi

So, when I su to root, all my commands go into:

.sh_history_gwild

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
curt larson_1
Honored Contributor

Re: user profiles and shell environments

here is a few examples of things that can be done
curt larson_1
Honored Contributor

Re: user profiles and shell environments

these are just text files, but i can only attach one at a time
curt larson_1
Honored Contributor

Re: user profiles and shell environments

this is for the root user, attached is for a non root user

################################################################################
#
# File: root's .profile
#
# If the variable SECURITY is /sbin/true then
# login security information will be shown.
#
################################################################################
# set -x
SECURITY=/sbin/false

set -u

# Just for root

PATH=$PATH:/sbin
PATH=$PATH:/usr/sbin
PATH=$PATH:$HOME/bin

# Perform this next stuff only if we are interactive

if $INTERACTIVESHELL
then

#
# If using VUE or CDE, set the appropriate TERM type to use for
# our default prompt (and then unset TERM after)...
#
set +u
if [ "$VUE" ]
then
TERM=hpterm
elif [ "$DT" ]
then
TERM=dtterm
fi
fi

# End of interactive tty-based settings


#
# To avoid improper environment inheritance, unset TERM if currently
# logging in to VUE or CDE...
#
if [ "$VUE" -o "$DT" ]
then
unset TERM
fi

# You don't want to do this with CDE or other X session managers, most
# effectively do it for you, and doing it unconditionally can cause trouble...

if [ ! "$DT" -a ! "$SESSIONTYPE" ]
then
XENVIRONMENT=$HOME/.Xdefaults
export XENVIRONMENT
fi

#
# Track down the incoming $DISPLAY device (if necessary and possible)
# There might not be a controlling tty device (found in /etc/profile)
# so handle a batch startup condition too.
#
if [ ! "$DISPLAY" -a ! "$REMOTEHOST" ]
then
if $TTYDEVICE
then
DISPLAYHOST=$(who -muR | awk '{print $NF}')
DISPLAYHOST=${DISPLAYHOST%%:0.0}
DISPLAY=$DISPLAYHOST:0.0
echo
echo "TERM=$TERM, DISPLAY=$DISPLAY"
fi
else
if [ ! "$DISPLAY" ]
then
DISPLAY=$REMOTEHOST:0.0
fi
fi
if [ "$DISPLAY" ]
then
export DISPLAY
fi

set -u
# Set up shell environment:

MAIL=/var/mail/$(whoami)
EDITOR=/usr/bin/vi
HISTSIZE=200
HISTFILE=$HOME/.sh_history
export MAIL EDITOR HISTSIZE HISTFILE

# Setup a default printer (must customize as required)

export LPDEST=LPDESTisNOTset

# Set root's shell to always timeout so forgotten logins will go away

readonly export TMOUT=3600

# If interactive, setup some standard things

if $INTERACTIVESHELL
then

#
# Single char aliases
#
alias h='fc -l'
alias m='more -e'
alias n=nslookup
alias c="tput khome;tput clear"
alias e=expand_alias
alias f='fnlookup -o'

# Other quickies

alias lp='lp -onb'
alias hgrep='fc -l 1 | grep'
alias ls='/usr/bin/ls -aF'
alias ll='/usr/bin/ll -aF'
alias gpm='nohup /opt/perf/bin/gpm -sharedclr -nosave -bg navy -fg white > /dev/null & >
/dev/null'

# Safety aliases

alias mv='/usr/bin/mv -i'
alias cp='/usr/bin/cp -i'
alias rm='/usr/bin/rm -i'

# Character-mode versions for sam and swinstall

alias samc="(unset DISPLAY;sam)"
alias swinstallc="(unset DISPLAY;swinstall)"
alias cx="chmod u=+x,g=+x,o=+x"
alias xjdm="/opt/hpnp/bin/xjdm -bg SlateBlue -fg white"

#
# Useful shell setups
#
# -o vi = vi mode for command history
# -o viraw = raw character-by-character processing in vi mode
# -o ignoreeof = Do not exit from the shell on end-of-file
# -o markdirs = Append a trailing / to all directory name generation
# -o monitor = An interactive shell associates a job with each pipeline.

set -o vi -o viraw set -o ignoreeof -o markdirs -o monitor

# Terminal character enhancements

HV=$(/usr/bin/tput smso)
IV=$(/usr/bin/tput bold)
NV=$(/usr/bin/tput rmso)
UL=$(/usr/bin/tput smul)
EE=$(/usr/bin/tput sgr0)

# Setup the prompt string $PS1

if [ "$LOGNAME" = "root" ]
then
SUFFIX="#"
else
SUFFIX="$"
fi

HN=$(/usr/bin/hostname)
PS1='${HV}${HN} ${IV}${PWD##${PWD%/*/*}/}${EE} ${SUFFIX} '

#
# Else, just set a simple $PS1 in case it's needed
#

else
PS1='${HN}: ${PWD##${PWD%/*/*}/} ${SUFFIX} '
fi

# For root users, show who else mught be logged on as root too

ROOTERS=$(who -R | grep root | wc -l)
if [ $ROOTERS -gt 1 ]
then
echo
echo "${HV}Note: ${IV} $ROOTERS root users currently logged in${EE}"
echo "----------------------------------------"
who -R | grep root
echo
echo "${HV} ${EE}"
echo "${HV} ${IV} Be sure to coordinate root efforts ${NV}${HV} ${EE}"
echo "${HV} ${EE}"
echo
fi

# Security information for user to review
# If NOSECURITY exists, bypass these lists

if $SECURITY
then
echo "\n${UL}\t\t\t\tSecurity information\t\t\t\t${EE}"

# $NUM is the number of bad logins, good logins and su attempts to list

NUM=5
MYUSERID=$(/usr/bin/whoami)

# Bad logins

if [ -r /var/adm/btmp ]
then
echo "\n${UL}Last $NUM FAILED $MYUSERID logins:${EE} (lastb -R -$NUM $MYUSERID)"
/usr/bin/lastb -R -5 $MYUSERID
fi

# Successful logins

echo "\n${UL}Last $NUM succesful $MYUSERID logins:${EE} (last -R -$NUM $MYUSERID)"
/usr/bin/last -R -5 $MYUSERID

# SU attempts (good and bad)

if [ -r /var/adm/sulog ]
then
echo "\n${UL}Last $NUM su attmpts for $MYUSERID:${EE} (grep $MYUSERID
/var/adm/sulog)"
if [ $(/usr/bin/grep $MYUSERID /var/adm/sulog \
| wc -l \
| awk '{print $1}') -gt 0 ]
then
/usr/bin/grep $MYUSERID /var/adm/sulog \
| /usr/bin/sort -r \
| /usr/bin/head -$NUM
else
echo "(none)"
fi
fi

# End of security reports

fi
echo

# Lastly: run any local root customizations for this machine

if [ -r $HOME/.localprofile ]
then
. $HOME/.localprofile
fi


Mladen Despic
Honored Contributor

Re: user profiles and shell environments

Great responses! Thank you, all.

Mladen