隐藏Expect命令的输出

时间:2016-11-28 21:36:44

标签: bash shell expect

所以我有以下代码,无法弄清楚如何只显示一个发送命令。我只需要df -h send命令的结果。

#!/usr/bin/env bash
echo "Updating Source..."

/usr/bin/expect << EXPECT
    log_user 0;
    spawn  -noecho ssh -p 7742 user@location
    expect "username:"
    send "username\r"
    expect "password:"
    send "password\r" 
    send "shell\r"
    send "df -h\r" 
    send "exit\r"
    sleep .5
    send "exit\r"
    interact
EXPECT

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

#!/usr/bin/env bash
echo "Updating Source..."

/usr/bin/expect << EXPECT
    log_user 0;
    spawn  -noecho ssh -p 7742 user@location
    expect "username:"
    send "username\r"
    expect "password:"
    send "password\r" 
    send "shell\r"
    log_user 1;
    send "df -h\r"
    log_user 0;
    send "exit\r"
    sleep .5
    send "exit\r"
    interact
EXPECT