linux - 提供一个脚本从另一个脚本的选项输入

标签 linux shell batch-file

使用 putty 登录时自动登录脚本运行并要求选择选项。是否可以通过另一个批处理文件/脚本提供输入? 例如:当我使用批处理文件登录说 1.1.1.10 时,它会弹出窗口,要求输入从 1 到 10 的选项号。我想自动输入该选项。

最佳答案

既然您提到了 putty,我假设您正在 Windows 工作站上工作。我不确定您是否熟悉自动热键,但是您可以使用自动热键代码片段轻松完成此操作。像这样的事情:

^+P::                                              ; shift-ctrl-P is the hotkey combo to activate this code
send #r                                            ;open windows run dialog box
send \path\to\putty.exe hostname.domain.com{enter} ; stary putty and connect to server
sleep 5000                                         ; wait 5 seconds for connection to establish
send username{enter}                               ; types your username and hits enter
sleep 1000                                         ; wait 1 second for password prompt
send password{enter}                               ; types your password and hits enter
sleep 5000                                         ; wait 5 seconds for your autologin script to run and display menu
send 1{enter}                                      ; type your selection and hit enter (assumes your selection is "1" here
return                                             ; ends code snippet

您可以根据您的具体情况更改击键和等待时间。

autohotkey是一款免费软件(供个人使用),可以从http://www.autohotkey.com获取

关于linux - 提供一个脚本从另一个脚本的选项输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23535146/

相关文章:

batch-file - 在IF语句中设置变量(Windows批处理文件)

linux - 使用 docker-machine 更改文件组

linux - 以下命令中-print0的含义是什么

linux - 尝试在 shell CLI 中将 .JPEG 重命名为 .jpg

Linux shell : Changing decimal (float) separator from dot to comma

python - 在 python 中复制 shell 环境以执行 bash 命令

windows-7 - 登录时在 Windows 7 中自动运行 bat 脚本

Windows 批处理脚本 : Redirect ALL output to a file

linux - 在 Linux 上的 gphoto2 中连拍拍摄照片

linux - 汇编语言编译器