【问题标题】:running expect scripts that are in gist.github.com运行 gist.github.com 中的期望脚本
【发布时间】:2013-02-25 11:03:52
【问题描述】:

我知道我可以使用以下命令运行放置在 gist.github.com 中的 bash 脚本:

bash -c "$(curl -fsSL https://raw.github.com/gist/5126919)" <arg0> <arg1>

我如何对期望脚本执行相同的操作?

我这里有一个示例:

https://gist.github.com/simkimsia/5126919

#!/usr/bin/expect -f

set CHANGESHELL_FOR_USER [lindex $argv 0];
set PASSWORD_OF_USER [lindex $argv 1];

########################################
## switch to another user
## read this http://stackoverflow.com/a/1988255/80353
########################################
sudo -u $CHANGESHELL_FOR_USER -H sh -c "chsh -s /bin/bash" 

expect "*?assword:*" {send -- "$PASSWORD_OF_USER\r";}
expect eof

我的目的是为特定用户 chsh。

【问题讨论】:

    标签: bash expect gist


    【解决方案1】:

    Bash 和 ksh 支持进程替换,因此您可以这样尝试:

    expect &lt;(curl ...) arg1 arg2 ...

    我能想到的唯一问题是$argv0的值不是我们通常所期望的。您可以考虑在脚本中对其进行硬编码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-05
      • 2014-09-20
      相关资源
      最近更新 更多