解决方法: echo + | (管道)
始终提示输入密码
后来查看了下sudo命令的使用
the standard input instead of the terminal device. The
password must be followed by a newline character.
因此,之前的命令修改如下:
OK可以work
PS:网上说Shell 的expect工具,专门用来实现自动交互功能的,由于我的需求挺简单的,暂时用不到,后面有用的话,再做研究。
开始使用
echo "admin" | sudo service tomcat7 stop始终提示输入密码
后来查看了下sudo命令的使用
man sudo
发现有如下的解释:
-S The -S (stdin) option causes sudo to read the password fromthe standard input instead of the terminal device. The
password must be followed by a newline character.
因此,之前的命令修改如下:
echo "admin" | sudo -S service tomcat7 stopOK可以work
PS:网上说Shell 的expect工具,专门用来实现自动交互功能的,由于我的需求挺简单的,暂时用不到,后面有用的话,再做研究。
解决sudo命令不读取管道密码的问题

本文介绍了一种解决sudo命令无法通过管道传递密码的问题的方法,通过使用-S选项让sudo从标准输入中读取密码,从而避免了交互式提示。此外,还提到了一种更为复杂的自动交互解决方案——Shell的expect工具。
8195

被折叠的 条评论
为什么被折叠?



