Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

On my node node_name I've got $JAVA_HOME and other environment variables set in /etc/profile. I'm aware (found that out) that knife ssh isn't a login shell, and so doesn't load the environment variables. Is there a way to load the environment variables without having to source it? Right now I'm forced to do

knife ssh 'name:nod_name' 'source /etc/profile; echo $JAVA_HOME'

I'm chaining in a few commands during knife ssh including some of the environment variables and loading the /etc/profile just makes that longer. Is there a way to load the /etc/profile during knife ssh?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
212 views
Welcome To Ask or Share your Answers For Others

1 Answer

This has nothing to do with knife ssh, it is just how SSH works for commands executed directly over a connection. You can alternatively run a command like bash -l -c "something". In general you can't count on any specific way of setting env vars in non-interactive sessions as being portable, so caveat emptor.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...