开发者

Accessing environment variables of another machine in Ruby

I am writing ruby scr开发者_运维百科ipt which accesses folders on other networked machines (windows). I need to know the environment variables on that machine, how do I do this? Once I get access to the remote environment variables, It will help me know where the software has been installed.

Thanks N.I


Does your solution need to be pure Ruby? If not, you could use the PsExec command. The following will output the environment variables on remote (for the current user):

psexec \\remote cmd /C set

This works by executing cmd remotely and passing it the command set to run.

The following Ruby code will run PsExec and return the remote environment variables as a Hash:

Hash[*`psexec \\\\remote cmd /C set`.split("\n").
  collect {|i| i.split('=', 2)}.flatten]


You need to deploy simple HTTP-server with helper script that print to the output stream information you need (i.e environment variables, etc). Next you have to call that script from remote machine, and parse results.

Or, without server, add scheduled task to your remote machine, that writes once per day required information to some known file (I mean to file at fixed path). It's much simpler, however you'll see delayed information changes.


I would recommend the ruby WMI interface. As long as you have a fairly modern Windows (XP and up IIRC), you can fetch environment variables from remote machines easily. Google for more information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜