当前位置:  技术问答>linux和unix

如何在bash脚本中执行sudo时自动输入用户密码?

    来源: 互联网  发布时间:2017-04-08

    本文导语:  例如: ./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..." 其中有一条指令为...

例如:
./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无需输入密码?

|
make.ep

#!/usr/bin/expect
set timeout 3600
spawn sudo make install
expect "Password:"
send "feir"
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

|
貌似有个方法是使用expect。。

|
前几天看了一个脚本说,许多ssh翻墙的为了实现掉线自动登录,通常用expect来实现交互情况下密码的输入
http://blog.csdn.net/Lethe1989/archive/2010/01/25/5253155.aspx

|
echo  "你的密码" |sudo  make install   
这样?

|
visudo

|
就听说过expect,还没用过,长见识了

|

长见识了!

|
sudo make install

    
 
 

您可能感兴趣的文章:

  • centos系统运行脚本,显示bash进程,能否以脚本名字显示?
  • 求高手给写一个bash脚本,功能很简单,就是去执行某一个php脚本
  • 求bash脚本思路?
  • cgi 中调用bash脚本问题?急 急 急
  • 关于arm linux下的别名配置脚本如何在进入用户时让shell执行的问题,如bashrc,profile,.bash_profile等脚本,寻求高手解答
  • 在bash里,脚本的第一行怎么write?(sorry,keyboard damaged)
  • 有没有方法可以使用脚本批量修改bash环境变量
  • bash脚本程序如何得到自身的执行路径?
  • 求教:编写一个bash脚本程序执行一个./file 程序
  • bash脚本换行符。
  • 三个容易bash脚本,高分求解
  • 关于bash脚本中sed的用法?
  • 脚本能修改bash的环境变量吗
  • bash脚本
  • Linux C编程一站式学习,高级shell Bash脚本编程指南,
  • 求教,bash脚本如何调用含键盘输入的可执行文件。
  • 【高级Bash脚本编程指南]贡献一点点,给大家用
  • bash脚本的问题,为何循环体中不能修改变量的值?
  • 包含上层bash脚本怎么搞(急用)?
  • 求一个bash脚本判断网络通断的思路
  • 如何配置bash,使得输入vi时,运行的是vim?
  • zhcon在bash中不能显示/输入中文,而vi等编辑器中可以。
  • bash的for循环输入重定向问题
  • 使用gcc编译一个程序a.c成a.out,输入a.out运行,提示bash:a.out:command not found,咋回事?
  • 输入logout,提示“bash:logout:不是登录shell,请用"exit"”
  • 为什么 a.out明明存在 ,而我在shell中输入a.out却说bash: a.out : command not found?
  •  
    本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
    本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • 请问bash中如何获取一个项目目录下的执行文件的文件名?
  • 为什么在shell开头要执行/home/XXX/.bash_profile
  • 启动Linux终端时不能自动执行.bash_profile文件
  • Redhat 的 fedora版本是刚刚安装好的,就发现了问题:终端里执行很多命令时提示:bash: xxx 权限不够
  • BASH中如何判断程序是否执行完毕
  • .bash_profile 文件修改之后不执行,在线等~-
  • bash脚本下,循环只执行一次就退出
  • crontab中执行bash脚本问题
  • 为什么C语言用execl执行bash shell脚本会出现Exec format error?
  • linux bash shell命令:grep文本搜索工具简介
  • . ./.bash_file 与 ./.bash_file的区别?
  • linux bash shell命令:文本搜索工具grep中用于egrep和 grep -E的元字符扩展集
  • 为什么每次启动bash都出现bash:test:a:binary operaotr expected
  • linux bash shell命令:文本搜索工具Grep命令选项及实例
  • linux RHEL 5.6 在root用户下. .bash_profile 或source .bash_profile 报错
  • linux bash shell命令:文本搜索工具grep正则表达式元字符集(基本集)
  • Ubuntu中如何配置shell(bash)的环境
  • 如何在ubunt下面安装两个bash
  • bash 不能使用括号,求助
  • 如何在redhat下安装bash?
  • bash和Korn shell学哪个比较好
  • 请问root的bash的环境变量放在哪个文件中啊?
  • linux(redhat9)中在哪里设环境变量,.bash_profil在哪里啊?
  • BASH Debugger
  • .bashrc和.bash_profile有什么区别
  • . /root/.bash_profile
  • Bash架构问题
  • bash的控制终端
  • bash 与shell 什么关系?
  • -bash-3.2# Argument list too long 到底是怎么回事呀?


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,