Get the remote python version with fabric
I am new to Fabric, and so far I am able to use all the basic functionality, connect and execute bash commands. But I am trying to execute python commands too to verify the running version and other things.
but as far as the version goes, how can I get the remote python version with fab.
UPDATE (Error details): Here is the output I got
[192.168.3.139] run: python --version
[192.168.3.139] out: Python 2.7.1+
[192.168.3.139] out:
Traceback (most recent call last):
File "/home/mo/Projects/mazban/lib/python2.6/site-packages/fabric/main.py", line 723, in main
task开发者_运维技巧(*args, **kwargs)
File "/home/mo/Projects/mazban/mazban/fabfile.py", line 203, in firstrun
version = run("python --version").split()[2]
IndexError: list index out of range
Disconnecting from 192.168.3.139... done.
This is probably the easiest solution:
version = run("python --version").split()[2]
Note: on my system, the first line of output is "BASHRC", which is why you need to do [2]
.
精彩评论