Re: Question about permissions used on onconfig and sqlhosts files
Posted in 2003
Topics: Server Administration, Networking & sqlhosts Configuration
Paul Watson wrote:
>
> re: scripts, all our scripts source a single environment file so if
> you do need to change INFORMIXDIR, edit one file and every body knows
>
> On dev boxes, we just run things like on920, on931, se726 etc and
> these scripts flick the environment over
Because it's friday, the day for Fun at Work, but without trying to frighten
the horses, here's my replacement for the cd built-in command which
automatically flips environments as you move around. Read it and weep with
horrified confusion :-))
<code type="ksh">
function chdir {
typeset result opwd="$OLDPWD" spwd="$PWD"
# if you export $CDHOME, it becomes the alternative
# target when you run cd without args
#
[[ $# -gt 0 ]] || set -- "${CDHOME-$HOME}"
cd "$@"
result=$?
if [[ $result -ne 0 ]]; then
# the cd may have been less than successful
# so return to last good place
# this is because multi-arg cd can do ... clever things
#
cd "$spwd" 2>&-
OLDPWD="$opwd" # restore OLDPWD
return $result
fi
# restore OLDPWD if we haven't actually changed PWD
[[ "$PWD" = "$spwd" ]] && OLDPWD="$opwd"
# search up the directory tree for a .env script
# will NOT find one in / - I think that's Good.
#
typeset ef dir="$PWD"
while [[ -z "$ef" && -n "$dir" ]]; do
if [[ -x "$dir/.env" ]]
then ef="$dir/.env"
else dir="${dir%/*}"
fi
done
# check for change of environment
if [[ -n "$ef" && "$ef" != "$ENV_FILE" ]]; then
# stop the old environment (if it was started)
[[ -n "$ENV_FILE" && -x "$ENV_FILE" ]] && . "$ENV_FILE" stop
# move to new environment and start it
export ENV_FILE="$ef"
. "$ENV_FILE" start
fi
return 0
} # chdir
alias cd=chdir
</code>
This will probably work in bash - maybe requiring a bit of work (but I don't
care because bash is such an appalling shell)
I only define this for interactive shells (ie on the command line) by
wrapping the whole lot in
if [[ $- = *i* ]]; then
....
fi
And in fact, the ideal place for this is in the $ENV file (normally .kshrc
in home directory). This way all interactive sub-shells get it.
You don't need it available in scripts because you can code them to "dot in"
the environment files. Which I'd better describe...
This chdir function does the cd business, and then searches up the directory
tree for a file called .env. If it is found, and if it's full pathname is
different from the previous .env file found, then it:
1) dot's in the old .env file with a stop argument. This can be detected
within the .env script and used to "stop" the previous environment
2) dots in the new .env file with a start argument. This can be detected
within the .env script and used to start the new environment.
the .env files must have execute permission - this allows you to disable 'em
without destroying them. You need to decide whether you want to block this
code for user accounts such as root.
Here's a sample of one of my .env scripts:
case "$1" in
start)
echo "You have entered The Funky Zone"
set -a # causes automatic export of all variables
funky=$PWD
# a small list of environment-poking functions
wacgen -d
fourjays 516
informix 940
GetModules $funky
INFORMIXSERVER=director
DBDATE=dmy4/
DBPATH=$wacgenlib/forms.$waclibext:$FGLDIR/resources FGLDBPATH=$funky
FGLPROFILE=$FGLDIR/etc/fglprofile.funky
[[ -z "$__PATH" ]] && __PATH="$PATH"
PATH=$wacgen/bin:$wacgen/bin.port:$FGLDIR/bin:/opt/icon/bin:$INFORMIXDIR/bin
PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin
set +a # switch off automatic export of vars
;;
stop)
echo "Disco Stu says, GoodBye from The Funky Zone! Oooh yeahhh!"
wacgen -d
GetModules -d
set -a
# clean-up any $VARS that might interfere with other envs
INFORMIXSERVER=maloo
[[ -n "$__PATH" ]] && PATH="$__PATH"
set +a
;;
esac
You where really bored when you wrote that :-))) re: bash shell, we've got a web company who had an external security review, the company that did the review refused to pass the systems as secure if bash was installed on any of the production servers (Solaris). Andrew Hamm wrote: > > Paul Watson wrote: > > > > re: scripts, all our scripts source a single environment file so if > > you do need to change INFORMIXDIR, edit one file and every body knows > > > > On dev boxes, we just run things like on920, on931, se726 etc and > > these scripts flick the environment over > > Because it's friday, the day for Fun at Work, but without trying to frighten > the horses, here's my replacement for the cd built-in command which > automatically flips environments as you move around. Read it and weep with > horrified confusion :-)) > > <code type="ksh"> > function chdir { > typeset result opwd="$OLDPWD" spwd="$PWD" > [cutting] > > This will probably work in bash - maybe requiring a bit of work (but I don't > care because bash is such an appalling shell) > [cutting] -- Paul Watson # Oninit Ltd # Growing old is mandatory Tel: +44 1436 672201 # Growing up is optional Fax: +44 1436 678693 # Mob: +44 7818 003457 # www.oninit.com #