pkg_hostname

Package: WA2L/edrc 1.5.57
Section: Library Commands (3)
Updated: 16 August 2008
Index Return to Main Contents

 

NAME

pkg_hostname - resolve package- or host name for the current dir

 

SYNOPSIS

edrc/lib/pkg_hostname

 

AVAILABILITY

WA2L/edrc

 

DESCRIPTION

return cluster package name the current working directory is related to.

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.

 

OPTIONS

-

 

ENVIRONMENT

$OSID
osid of the operating system as resolved by osid(3). If $OSID is not set the OS-id is resolved by the pkg_hostname command.

 

EXIT STATUS

0
always.

 

FILES

etc/pkg_hostname.cfg
configuration file of pkg_hostname. In this file the mapping between the filesystems and the related cluster package is defined.

 

EXAMPLES

1) usage of pkg_hostname in the user .profile and .kshrc

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

:
:

~/.kshrc:

:
:

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'

:
:

2) usage of pkg_hostname in a script

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

:
:

 

SEE ALSO

bash(1), edrcintro(1), getfilesystem(3), ksh(1), pkg_hostname.cfg(4), server_environment(3)

 

NOTES

-

 

BUGS

If the getfilesystem(3) command does not exist for a certain operating system, a slightly less precise mechanism is used to resolve on which filesystem the current working directory is located.

 

AUTHOR

pkg_hostname was developed by Christian Walther. Send suggestions and bug reports to wa2l@users.sourceforge.net .

 

COPYRIGHT

Copyright © 2008 Christian Walther

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.


 

Index

NAME
SYNOPSIS
AVAILABILITY
DESCRIPTION
OPTIONS
ENVIRONMENT
EXIT STATUS
FILES
EXAMPLES
SEE ALSO
NOTES
BUGS
AUTHOR
COPYRIGHT

This document was created by man2html using the manual pages.
Time: 16:54:00 GMT, August 28, 2024