bash - 为什么这个命令不从文件中获取输入,尽管重新编排?
问题描述
执行时,cisco anyconnect VPN 客户端从终端获取 VPN IP、密码和其他一些输入。但是,我不是每次都输入,而是在文件中记下值并尝试将文件重定向到 vpn 客户端命令。
/opt/cisco/anyconnect/bin/vpn < vpndetails.txt
但是,该命令似乎忽略了文件重定向并仍然提示输入。这怎么可能?代码是否从其他文件描述符(不是 0)读取并仍然从终端读取?可能吗?
注意:我知道将密码存储在文件中不是一个好习惯,但我现在不在乎。
解决方案
“有没有可能”这个问题的答案是“是”。
如 Chepner 的评论中所解释的那样,anyconnect vpn 的代码可能是 /dev/tty 作为一个有趣的练习,试试这个脚本:
#! /bin/sh
read -p "STDIN> " a
read -p "TERMINAL> " b < /dev/tty
read -p "STDIN> " c
echo "Read $a and $c from stdio and $b from the terminal"
并且,例如,ls / | bash this_script.sh
。
但是,如果您希望在没有密码的情况下使用 Cisco 自动连接,则应调查 Always On with Trusted Network 检测功能和用户证书。
写信/dev/tty
希望它会被脚本接收是行不通的:
ljm@verlaine[tmp]$ ls | bash test.sh &
[3] 10558
ljm@verlaine[tmp]$ echo 'plop' > /dev/tty
plop
[3]+ Stopped ls | bash test.sh
ljm@verlaine[tmp]$ fg
ls | bash test.sh
(a loose enter is given)
Read a_file and b_file from stdio and from the terminal
推荐阅读
- c# - IndentityServer4 客户端权限/声明的 ASP.NET Core API 控制器操作验证
- excel - 如何为同一变量分配更多范围?
- vue.js - 如何通过某些属性从页面中获取相同的 Vue 组件
- javascript - 如何在复选框选中状态和未选中状态下添加和减去列表数据反应本机
- json - CFML/JS 从普通 SQL 创建嵌套的 JSON/数组
- java - 为什么 Mockito.mock() 无法模拟带有 Hystrix 注释的类?
- javascript - 如何使用货币管道在组件中获取最多 2 位十进制数字的值?
- selenium - 从会话 ID 获取主机名
- angular - 是否可以在 weblogic 12c 中部署 Angular 应用程序?
- python - 如何在多个 GPU 之间拆分一个 Keras 模型