如何在bash脚本中执行sudo时自动输入用户密码?例如:./configure --prefix/usr --with-contrib-pluginsal
如何在bash脚本中执行sudo时自动输入用户密码? 例如:
./configure --prefix=/usr --with-contrib-plugins=all,-byogames,-Cccc,-cbkoders,-codesnippets,-copystrings,-envvars,-headerfixup,-libfinder,-NassiShneiderman,-exporter make -j2 sudo make install read -n1 -p "Press any key to continue..." 其中有一条指令为:sudo make install
那么,在执行这一指令时是需要输入用户密码的,这里就避免不了存在交互。
如何实现此时自动输入密码? 或者让
只在这一次 sudo无需输入密码?
[解决办法] echo "你的密码"
[解决办法] sudo make install
这样?
[解决办法] visudo
[解决办法] 貌似有个方法是使用expect。。
[解决办法] 前几天看了一个脚本说,许多ssh翻墙的为了实现掉线自动登录,通常用expect来实现交互情况下密码的输入
http://blog.csdn.net/Lethe1989/archive/2010/01/25/5253155.aspx
[解决办法] 就听说过expect,还没用过,长见识了
[解决办法] 引用: 引用: 前几天看了一个脚本说,许多ssh翻墙的为了实现掉线自动登录,通常用expect来实现交互情况下密码的输入 http://blog.csdn.net/Lethe1989/archive/2010/01/25/5253155.aspx 估计只能用expect了 别的想不到啥方法了 #!/usr/bin/expect set timeout …… 长见识了!
[解决办法] sudo make install<<EOF
your-password
EOF
[解决办法] make.ep
#!/usr/bin/expect set timeout 3600 spawn sudo make install expect "Password:" send "fei\r" interact#chmod +x make.ep
make.sh
#!/bin/sh ./configure --prefix=/usr --with-contrib-plugins=all,-byogames,-Cccc,-cbkoders,-codesnippets,-copystrings,-envvars,-headerfixup,-libfinder,-NassiShneiderman,-exporter make -j2 ./make.ep