linux下用expect登陆远程机子执行指令
时间:2024-05-17 05:10:50 点击:326

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

最新游戏更多

最新软件更多

  • 玩家推荐
  • 游戏攻略

北航游戏网 Copyright(C) 2008- 600435.cn All Rights Reserved!

苏ICP备17061231号| 免责声明