shell脚本实现ssh自动登录远程服务器示例: #!/usr/bin/expect spawn ssh root@192.168.22.194 expect "*password:" send "123\r" expect "*#" interact Expect是一个用来处理交互的命令.借助Expect,我们可以将交互过程写在一个脚本上,使之自动化完成.形象的说,ssh登录,ftp登录等都符合交互的定义.下文我们首先提出一个问题,然后介绍基础…
expect简介 expect是一款自动化的脚本解释型的工具. expect基于tcl脚本,expect脚本的运行需要tcl的支持. expect对一些需要交互输入的命令很有帮助,比如ssh ftp scp telnet.远程登录linux服务器的时候,ssh命令需要手工输入密码,当登录多台机器的时候就会非常繁琐.expect就可以根据设定的规则,自动帮我们输入密码,大大节省了时间. expect安装 sh-4.2# yum install expect # 首先需要配置yum源,linux大部…
[root@node2 ssh]# cat auto_ssh.sh #!/usr/bin/expect -f ########################################## #通过SSH服务将id.pas.pub公钥推送到目标服务器实现免密登陆 #参数:1.system_username # 2.system_password # 3.system_hostname # 4.CommandList [多个命令间:间隔] #返回值: # 0 成功 # 1 参数个数不正确 #…
Linux环境下只有在机器20.200.254.18上ssh dataconv@20.200.31.23才能连接到23的机器,而且还需要输入密码(每次都需要输入地址,密码很烦),所以利用expect写了个脚本. 脚本如下: #!/usr/bin/expect spawn ssh dataconv@20.200.31.23 expect "*password:" send "HF*dv303\r" interact 其中第一行 /usr/bin/expect是表示ex…
在linux系统下,用weblogic部署了两套应用,创建了两个虚拟主机,一个主机指向www.test1.com, 另一个虚拟主机指向www.test2.com. 一套应用指定一台虚拟主机. 修改/etc/hosts文件,添加下列内容: 127.0.0.1   www.test1.com 127.0.0.1   www.test2.com 为绝后患,注销后重新登录linux系统,启动weblogic服务器,就可以使用上面两个域名,在本机访问了 windows下的配置 打开文件:c:\window…
可能有多个网卡包括虚拟网卡,需要进行排除 String ip = ""; try { Enumeration<?> e1 = NetworkInterface.getNetworkInterfaces();//获取多个网卡 while (e1.hasMoreElements()) { NetworkInterface ni = (NetworkInterface) e1.nextElement(); if(("eth0").equals(ni.getNa…
#!/bin/expect -- ########################################## zhichao.hu #Push the id.pas.pub public key to the target server through the SSH service to implement secret-free login. #Define an iplist Create an iplist file in the current directory. The…
#!/usr/bin/expect -f ########################################## hutu #Push the id.pas.pub public key to the target server through the SSH service to implement secret-free login. #Define an iplist Create an iplist file in the current directory. The co…
linux下各种集群搭建往往需要配置远程免密登录,本文主要描述了CentOs6.3系统下配置免密登录的详细过程. ssh远程登录,两种身份验证: 用户名+密码 密钥验证 机器1生成密钥对并将公钥发给机器2,机器2将公钥保存. 机器1要登录机器2时,机器2生成随机字符串并用机器1的公钥加密后,发给机器1. 机器1用私钥将其解密后发回给机器2,验证成功后登录 1.用户名+密码 如上图所示,机器1要登录到机器2 ssh 机器2的ip(默认使用root用户登录,也可指定,如:ssh a@192.168.…
有时候我们需要批量发送ssh命令给服务器,但是有可能有些服务器是新加入的,还没有配置ssh免密,这个时候就会提示我们输入yes/no 或者password等,expect脚本命令就是用于在提示这些的时候,自动为我们输入相应的文字 expect脚本 先看一段shell脚本,实现了ssh自动连接 #!/usr/bin/expect spawn ssh 192.168.1.241 expect "password" send "123456\r" expect "…