Kurt Franke a écrit :
<snip>
I use /proc/registry and loop through the entries in the environment directories
in the form
name=`cat $name`
All this is written to a .bat file with also added code to write a script out
to be sourced to get the environment settings
this long way around is used to automatically expand variables in registry keys
which may exist in keys of type REG_EXPAND_SZ
this is of course also a brake pad for the performance
I think for interactive logon this is tolerable
But for using it very often in a rsh manner a solution with good performance
would be preferred.
Hi,
the attached script only fork 5 processes (ps, grep, mount, find and
awk), and does not use any temporary files, so, it should not degrade
ssh logins performance.
existing environment variables are not overwritten.
Regards,
Cyrille Lefevre
--
mailto:cyrille.lefevre-li...@laposte.net
#!/bin/sh
#
# ssh-session-env.sh - script for installation in /etc/profile.d
#
# because in sessions started from sshd the windows system environment
# variables in general are not set except for some which are possible
# special handled (like PATH, etc.) and the windows user environment
# variables are not set from the actual user but from the user of the
# sshd server this script is used to build this environment settings in
# shells with bournish syntax which uses /etc/profile for initialization.
#
# authors: Kurt Franke, Cyrille Lefevre
#
# date: 06 march 2010
if ps -fp $PPID | grep -q "/usr/sbin/sshd$"; then
_IFS_=$IFS
IFS='
'
eval $(awk -v q="'" -v mp="$(mount --show-cygdrive-prefixes)" '
BEGIN {
sub(/.*\n/, "", mp)
sub(/[ \t].*/, "", mp)
}
{
var = FILENAME
sub(".*/", "", var)
var = toupper(var)
environ[var] = var == "PATH" && var in environ ? \
environ[var] ";" $0 : $0
}
END {
flag = 1
while (flag) {
flag = 0
for (var in environ) {
val = environ[var]
if (match(val,/%[^%]+%/)) {
flag = 1
subvar = substr(val, RSTART+1, RLENGTH-2)
subvar = toupper(subvar)
subval = subvar in environ ? \
environ[subvar] : ENVIRON[subvar]
if (subval !~ /%[^%]%/) {
head = substr(val, 1, RSTART-1)
tail = substr(val, RSTART+RLENGTH)
environ[var] = head subval tail
}
}
}
}
for (var in environ) {
if (var in ENVIRON)
continue
val = environ[var]
if (val ~ /;/ || val ~ /^.:/) {
gsub(/([a-zA-Z]):/, mp "/&", val)
gsub(/:/,"",val)
gsub(/\\/,"/",val)
gsub(/;/,":",val)
}
gsub(q, "\\"q, val)
print "export", var "="q val q
}
}
' /proc/registry/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Session\
Manager/Environment/* \
/proc/registry/HKEY_CURRENT_USER/Environment/* \
$(find /proc/registry/HKEY_CURRENT_USER/Volatile\ Environment -type f
2>/dev/null))
IFS=$_IFS_
unset _IFS_
fi
# eof
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple