IT猫扑网文章教程

分类分类

linux下用expect登陆远程机子执行指令

2015-06-28 00:00作者:网管联盟

  首先,要安装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 &123456r&

  expect &#&

  send &service crond restartr&

  expect eof

  注:expect的功能是很强大的,实现了无须人与系统交互的功能,已经成为SA的一个强大助手,要研究的彻底,还是需要大量的时间的。

展开全部

相关文章

说两句网友评论
    我要跟贴
    取消