pxssh如何发送线' N'提示" [Y / N]"

时间:2017-07-30 06:08:40

标签: python pexpect pxssh

我想使用pxssh为基于FreeBSD的产品NetScaler制作自动升级脚本。

我在FreeBSD上成功上传和tar固件并安装它。

使用promop"你想立即启用吗? [Y / N]" ,我的剧本未能发送线"否"它呢

错误代码是"' str'对象不可调用"

以下是输出:

$id=!empty( $_POST['id'] ) ? $_POST['id'] : 4147;

$text=!empty( $_POST['text_wall'] ) ? $_POST['text_wall'] : 'Humboldt Squid are vicious mofos';
$ville=!empty( $_POST['ville_wall'] ) ? $_POST['ville_wall'] : 'Bananas are generally yellow';
$date=date('c');


$replace=array( /* Replace these keys with these values */
    'date'          =>  $date,
    'text_wall'     =>  $text,
    'ville_wall'    =>  $ville
);


$keys=array_keys( $replace );

/* Contents from text file ~ trailing comma removed!!! */
$strjson='[
            {"ID":"4215","date":"2017-05-24T05:41:44","text_wall":"Petite photo de Valence prise dimanche ","image_wall":"https:\/\/www.originsphotography.eu\/model\/wp-content\/uploads\/2017\/05\/IMG_0056.jpeg","ville_wall":"Valence "},
            {"ID":"4147","date":"2017-05-18T15:15:02","text_wall":"#lyon #paris #valence Flixbus !","image_wall":"https:\/\/www.originsphotography.eu\/model\/wp-content\/uploads\/2017\/05\/IMG_0031.jpg","ville_wall":"Clermont-Ferrand"},
            {"ID":"3834","date":"2017-05-16T03:54:27","ville_wall":"Clermont-Ferrand","image_wall":"https:\/\/www.originsphotography.eu\/model\/wp-content\/uploads\/2017\/05\/SAM_7590.jpg","text_wall":"Nouvelle station de travail Dell E4300"}
        ]';
/* decoded file contents */
$json=json_decode( $strjson );


/* iterate over json object */
foreach( $json as $i => $obj ){
    /* Only replace for specified ID */
    if( $obj->ID==$id ){
        /* iterate through replacements */
        foreach( $replace as $key => $value ){
            $obj->$key=$value;
        }
    }
}
/* for testing */
echo '<pre>',print_r($json,true),'</pre>';

/* Convert back to json string */
$json=json_encode($json);

/* Save the file */
$bytes=file_put_contents('text.json',$json);

以下是我的剧本

You can also configure this feature anytime using the command line 
interface or the configuration utility.  Please see the documentation 
for further details.

Do you want to enable it NOW? [Y/N]
'str' object is not callable
[root@raynor NS_Auto_Upgrade]# 

1 个答案:

答案 0 :(得分:0)

我根本不了解您的图书馆,但我猜这个问题是这两行之间的冲突:

ssh_command.PROMPT='Do you want to enable it NOW? [Y/N]'
...
ssh_command.PROMPT('Reboot NOW? [Y/N]')

我不确定哪个是正确的,但是你可能要么两次都要调用PROMPT,要么两次分配它,而不是分配一次并调用另一个。