Expect script issue

后端 未结 2 1195
伪装坚强ぢ
伪装坚强ぢ 2021-01-19 13:16

I am trying to accomplish a simple job via expect. I want to create ssh keys using the \"ssh-keygen\" command on Linux VMs. My below expect code looks to be straight forward

相关标签:
2条回答
  • 2021-01-19 13:59

    The spawned program is likely sending more output than exactly what you're trying to match. That's why regular expression matching is so helpful.

    Try this:

    spawn ssh-keygen -t rsa
    expect -re {Enter file in which to save the key (/root/.ssh/id_rsa): $}
    send -- "\r"
    expect -re {Enter passphrase (empty for no passphrase): $}
    send -- "\r"
    expect -re {Enter same passphrase again: $}
    send -- "\r"
    
    0 讨论(0)
  • 2021-01-19 14:03

    I suppose you're exiting to quickly. This one works for me:

    #!/usr/bin/expect
    
    spawn ssh-keygen -t rsa
    expect "Enter file in which to save the key (/root/.ssh/id_rsa): "
    send  "\r"
    expect "Enter passphrase (empty for no passphrase): "
    send  "\r"
    expect "Enter same passphrase again: "
    send  "\r"
    expect
    
    0 讨论(0)
提交回复
热议问题