当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
linux下用expect登陆远程机子执行指令
发布时间:2010/7/28 11:55:45 来源:城市学习网 编辑:ziteng
  首先,要安装expect,linux expect的安装
  1.安装相应的包
  yum install -y tcl tclx tcl-devel
  2.下载expect-5.43.tar.gz包(我这里用的这个包,大家也可以用别的)
  根据参数,运行./configure
  ./configure --with-tcl=/usr/lib --with-tclinclude=/usr/include/tcl-private/generic
  3.make && make install  安装完毕
  简单的登陆别的机器执行命令,可行 (更详细的还得参考expect的有关说明)
  expect.sh
  #!/usr/local/bin/expect
  set timeout 10
  spawn ssh root@ip
  expect "*password*"
  send "123456\r"
  expect "#"
  send "service crond restart\r"
  expect eof
  注:expect的功能是很强大的,实现了无须人与系统交互的功能,已经成为SA的一个强大助手,要研究的彻底,还是需要大量的时间的。
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved