Le 03/05/2010 02:40, Larry Hall (Cygwin) a écrit :
On 5/2/2010 2:33 AM, Vincent Pelletier wrote:
Le dimanche 02 mai 2010 02:52:55, Larry Hall (Cygwin) a écrit :
You can add whatever variables you want and need to a script you can run
as part of the login or just after, depending on your needs.
So my question becomes:
Is it possible to get windows environment vars in a shell obtained via
ssh
(to avoid duplicating their definition in my .bashrc) ? Or is there a
way to
extend the set of vars sshd lets through to shell (I'm ok with having
to name
the variables I need, as long as I don't have to set their value
manually) ?
You can get the environment variables using 'env' (or 'set' in 'cmd.exe')
prior to invoking 'ssh'. You can then trim down the list to those that
you want. Putting those in a file that you can invoke shouldn't be hard.
around february 19, there was a discussion about to limit ssh
environment variables not including some windows ones !
since then, I use the following script to set the missing ones at
connection time...
you may comment the lines containing SECONDS.
it based on Kurt Franke's similar script in the idea.
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
_SECONDS_=${SECONDS:-$(date +%s)}
_IFS_=${IFS}
IFS='
'
eval "$( (
regtool -qv list /machine/SYSTEM/CurrentControlSet/Control/Session\
Manager/Environment
regtool -qv list /user/Environment
regtool -qv list /user/Volatile\ Environment
) |
awk -v q="'" -v mp="$(mount --show-cygdrive-prefixes)" '
function s2a(str, a, sep, i, t) {
if (sep == "") sep = " +"
split(str, t, sep)
for (i in t) a[t[i]] = ""
}
function uniqp(p, i, j, k, o, n, a, s) {
k = split(p, o, ":")
for (i = j = 1; i <= k; i++)
if (!(tolower(o[i]) in a))
a[tolower(n[j++] = o[i])] = ""
p = s = ""
for (i = 1; i < j; i++) {
p = p s n[i]
s = ":"
}
return p
}
BEGIN {
s2a("APPDATA CLASSPATH QTJAVA LOCALAPPDATA USERPROFILE VS90COMNTOOLS", \
noconvert)
s2a("HOMEPATH PATH TEMP TMP", override)
sub(/.*\n/, "", mp)
sub(/[ \t].*/, "", mp)
}
! /\\ \(\)$/ {
var = toupper($1)
$1 = $2 = $3 = ""
sub("^ +", "")
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 override) && var in ENVIRON)
continue
val = environ[var]
if (!(var in noconvert) && (val ~ /;/ || val ~ /^.:/)) {
gsub(/([a-zA-Z]):/, mp "/&", val)
gsub(/:/,"",val)
gsub(/\\/,"/",val)
gsub(/;/,":",val)
}
if (var == "PATH") val = uniqp(ENVIRON[var] ":" val)
gsub(q, "\\"q, val)
print "export", var "="q val q
}
}
')"
echo "elapsed: $(( ${SECONDS:-$(date +%s)} - $_SECONDS_ ))s"
IFS=${_IFS_}
unset _IFS_ _SECONDS_
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