BASH脚本的用户名/密码结构 [英] BASH scripting for username/password constructs

查看:89
本文介绍了BASH脚本的用户名/密码结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用NCAT开到一个ISP和它的端口的连接来写一个简单的bash脚本。

I want to write a simple bash script using ncat to open a connection to a ISP and its port.

第一个命令是:

nc address port

一旦这样做,我第一次提示提供用户名。我必须敲回车,然后我会提示您提供一个密码,然后我必须打一次ENTER

Upon doing this, I am prompted first to provide a username. I must hit ENTER, and then I will be prompted to provide a password and then I must hit ENTER again.

在这之后,我想开一个终端的工艺窗口。任何人都可以点我足够的资源,对于这种类型的脚本?

After this, I want to open a Terminal process window. Can anyone point me to sufficient resources for this type of scripting?

我知道用户名和密码了,但我也不太清楚如何解决的事实,我必须给它,然后按下回车键。我也不清楚如何打开一个新的终端proceses。

I know the username and password already, but I'm not too sure how to work around the fact that I must provide it and then hit enter. I'm also unsure how to open a new Terminal proceses.

在此先感谢!

推荐答案

查看expect脚本
预计

Check out expect script 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脚本的用户名/密码结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆