From f2487a22cd8108399a6861475d0a324016ea9c5f Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 13 Jan 2016 17:57:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20su=20-=20=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=8E=B7=E5=8F=96=20Env=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- connect.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/connect.py b/connect.py index 84a02048a..79b266e29 100755 --- a/connect.py +++ b/connect.py @@ -33,7 +33,10 @@ from jperm.ansible_api import MyRunner from jlog.models import ExecLog, FileLog login_user = get_object(User, username=getpass.getuser()) -remote_ip = os.environ.get('SSH_CLIENT').split()[0] +try: + remote_ip = os.environ.get('SSH_CLIENT').split()[0] +except (IndexError, AttributeError): + remote_ip = os.popen("who -m | awk '{ print $NF }'").read().strip('()\n') try: import termios