gpt4 book ai didi

bash - 用户名/密码结构的BASH脚本

转载 作者:行者123 更新时间:2023-12-02 14:12:50 26 4
gpt4 key购买 nike

我想使用ncat编写一个简单的bash脚本,以打开与ISP及其端口的连接。

第一个命令是:

nc address port

完成此操作后,首先提示我提供一个用户名。我必须按ENTER键,然后提示我提供密码,然后必须再次按ENTER键。

之后,我要打开一个终端进程窗口。谁能指出我有足够的资源来进行这种脚本编写?

我已经知道用户名和密码了,但是我不太确定如何解决必须先提供用户名然后按Enter的事实。我也不确定如何打开新的终端程序。

提前致谢!

最佳答案

查看期望脚本
Expect

例:

# Assume $remote_server, $my_user_id, $my_password, and $my_command were read in earlier
# in the script.
# Open a telnet session to a remote server, and wait for a username prompt.
spawn telnet $remote_server
expect "username:"
# Send the username, and then wait for a password prompt.
send "$my_user_id\r"
expect "password:"
# Send the password, and then wait for a shell prompt.
send "$my_password\r"
expect "%"
# Send the prebuilt command, and then wait for another shell prompt.
send "$my_command\r"
expect "%"
# Capture the results of the command into a variable. This can be displayed, or written to disk.
set results $expect_out(buffer)
# Exit the telnet session, and wait for a special end-of-file character.
send "exit\r"
expect eof

关于bash - 用户名/密码结构的BASH脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15373366/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com