If the directory is not related to a package the node name as resolved by hostname(1) is returned.
This command can be used to set the user's prompt depending on the current working directory of the user.
Set the user prompt dynamically to show the user on which cluster the current working directory is located.
~/.profile:
:
:
PKG_HOSTNAME=`~edrc/lib/pkg_hostname`
SH=${SH:=`basename $SHELL`}
case "$SH" in
        *bash*)
                PS1="[ \$PWD ]\n[ $LOGNAME@\${PKG_HOSTNAME} ][$SH]: "
                ;;
        *)
                PS1="[ \$PWD \]\\
[ $LOGNAME@\$PKG_HOSTNAME ][$SH]: "
                ;;
esac
:
:
:
:
ksh_cd(){
        if [ $# -eq 0 ]; then
                \cd $HOME
        else
                \cd "$*" 2>/dev/null
        fi
        ksh_cd_retval=$?
        if [ $ksh_cd_retval -eq 0 ]; then
                export PKG_HOSTNAME=`~edrc/lib/pkg_hostname`
        else
                echo "ksh: $*:  not found" >&2
                return $ksh_cd_retval
        fi
} # ksh_cd
alias cd='ksh_cd'
:
:
Suppose the script with the following cut-out is located in the path /cluster/dwh_db1/app/bin on the cluster packages in the TEST, PREPRODUCTION and PRODUCTION environment. The script has to run against different databases and has to mail a state information to different people depending on the package the script is running.
See also server_environment(3) for similar purpose.
#!/bin/sh
# Const
Scriptname=`basename $0
Scriptpath=`dirname $0`
case `cd $Scriptpath; pkg_hostname` in
        dwh_db1_tst)
                                Mail_to=fred.flintstone@acme.ch
                                Database=DWHTST
                                ;;
        dwh_db1_pre)
                                Mail_to=barney.boulder@acme.ch
                                Database=DWHPRE
                                ;;
        dwh_db1_prod)
                                Mail_to=pete.pepple@acme.ch
                                Database=DWHPROD
                                ;;
        *)
                                msg ERROR "check script!"
                                exit 1
                                ;;
esac
:
:
This is free software; see edrc/doc/COPYING for copying conditions. There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.