2017-02-09 1 views
0

Mac OS X上でPython 2.7とFabricを使用しています。最近、私のスクリプトがnodenameの変数を間違って保存していました。私はSSHのホスト。そのホストにログインするとエラーが表示され、そのエラーとその変数に実行( 'whatevercommand')が保存されるためです。たとえば、以下のコマンドで:エラーを無視し、Pythonの実行コマンドを使用するときに変数に保存しないようにとにかくPython:出力を変数に保存するためにFabric runコマンドを使用する

Could not chdir to home directory /home/yourdirectory/: No such file or directory (This is the error I get everytime I log into the machine) 

hostname (This is the hostname of the host I am logging into with Python) 

あり:

def saveHostname(): 
    with settings( 
     hide('running', 'warnings'), 
     shell='/bin/bash -c'): 

     date = run ('date') 
     host_type = run ('uname') 
     if "Linux" in host_type: 
      with hide('output'): 
       nodename = run('hostname -s') 
       print nodename 

それだけで「ノード名」を保存します?エラーを無視する

答えて

0

一つの方法は、ノード名

with hide('output'): 
    temp = run('hostname -s') 
    if "Could not chdir" not in temp: 
     nodename = temp 
     print nodename 
    else: 
     nodename = None 
+0

にそれを格納する前に、実行(「ホスト名-s」)の出力をテストしている。しかし、このエラーが発生しているホストのために、私はまだすることができませんnodenameだけを保存し、自分のスクリプトを他の機能に完成させる – user5578188

+0

実際のホスト名を正しく取得するには、ホストマシンでエラーを修正する必要があります。 –

関連する問題