• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
邹天得
博客园    首页    新随笔    联系   管理    订阅  订阅

执行expect报错

2.查看expect的路径,可以用

[zhuying@SOR_SYS opt]$ which expect 

/usr/bin/expect

[zhuying@SOR_SYS opt]$ view autosu.sh

3。确定脚本有可执行权限

chmod +x autosu.sh

#!/usr/bin/expect  -f            //这个expect的路径就是用which expect 查看的结果

spawn su - Oracle             //切换用户
expect "password:"           //提示让输入密码
send "99billzy\r"       //输入oracle的密码
interact                             //操作完成

这在root用户切换到oracle用户的时候特别的快,但是在其他用户切换到oracle的时候则需要等待一段时间!

另外需要注意的是:

不能按照习惯来用sh autosu.sh来这行expect的程序,会提示找不到命令,如下:

autosu.sh: line 3: spawn: command not found
couldn't read file "password:": no such file or directory
autosu.sh: line 5: send: command not found
autosu.sh: line 6: interact: command not found

因为expect用的不是bash所以会报错。执行的时候直接./autosu.sh就可以了。~切记!

posted on 2017-03-23 14:07  邹天得  阅读(4414)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3