Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 自动输入请求的密码_Bash_Go_Automation_Passwords_Command Prompt - Fatal编程技术网

Bash 自动输入请求的密码

Bash 自动输入请求的密码,bash,go,automation,passwords,command-prompt,Bash,Go,Automation,Passwords,Command Prompt,我正在运行一个Go程序,它要求我输入密码 脚本本身是这样完成的: fmt.Print("Enter password: ") bytePassword, err := terminal.ReadPassword(int(syscall.Stdin)) if err != nil { return } password := string(bytePassword) terminal来自golang.org/x/crypto/ssh/terminal和syscall来

我正在运行一个Go程序,它要求我输入密码

脚本本身是这样完成的:

fmt.Print("Enter password: ")
bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
    return
}
password := string(bytePassword)
terminal
来自
golang.org/x/crypto/ssh/terminal
syscall
来自
syscall
模块

我试着像这样运行脚本:

echo“mypassword”|/myscript

但它不起作用(正常情况下是这样的,当我被要求时手动输入密码)


如何在此处自动输入密码?我认为我做得对,但显然不行。

下面是我如何用bash脚本包装的
expect
来做的:

#!/bin/bash

PASS=secret_pass
CMND=YOUR_COMMAND

expect << EOF
spawn  $CMND
expect {
    "assword:" { send "$PASS\n" }
}
EOF
#/bin/bash
通行证
CMND=您的_命令

希望你能使用一个类似的工具。go有goexpect:这是否意味着我必须更改go脚本的代码?因为这是我不能做的事。实际上我只有二进制,我只知道它是怎么做的,但是我不能改变它。你可以用goexpect编写一个新的go程序。这个新程序使用goexpect运行您的“myscript”。关于术语的一个小注释:Go已编译。它不是一种脚本语言。因此,没有所谓的“围棋脚本”。
ssh_yes() {
assword='
    "assword:" { %s }
    "$ "       { send "exit\n" }
'
[[ $2 ]] && pass="send \"$2\n\"" || pass="exit"
printf -v assword "$assword" "$pass"
expect <<  EOF
spawn  ssh $1
expect {
    "yes/no" {
        send "yes\n"
        expect { $assword }
    }
    $assword
}
EOF
}