linux简单使用expect登陆远程计算机


 首先,要安装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的一个强大助手,要研究的彻底,还是需要大量的时间的


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3