你的位置:首页 > 操作系统

[操作系统]第三十一天



1、在A服务器上远程查看B服务器上的信息

[oldboy@A ~]$ ssh 192.168.1.113 hostnameB[oldboy@A ~]$ ssh 192.168.1.113 uname -r2.6.32-431.el6.x86_64[oldboy@A ~]$ ssh 192.168.1.113 uname -aLinux B 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux[oldboy@A ~]$ ssh 192.168.1.113 free       total    used    free   shared  buffers   cachedMem:    1020348   174508   845840     0   16092   61660-/+ buffers/cache:   96756   923592Swap:   1023992     0  1023992[oldboy@A ~]$ ssh 192.168.1.113 uptime 07:03:23 up 5 min, 1 user, load average: 0.01, 0.08, 0.06[oldboy@A ~]$ ssh 192.168.1.113 cat /etc/redhat-releaseRed Hat Enterprise Linux Server release 6.5 (Santiago)

2、实现expect无交互式批量分发密钥到B、C,即在没有建立免密码认证之前分发密钥实现非交互批量发布。
执行:

[oldboy@B ~]$ lsfenfa_sshkey.exp fenfa_sshkey.sh iplist[oldboy@B ~]$ sh fenfa_sshkey.sh[oldboy@B ~]$ cat fenfa_sshkey.sh#!/bin/sh./etc/init.d/functionsfor ip in `cat iplist`do#  expect fenfa_sshkey.exp ~/.ssh/id_dsa.pub $ip >/dev/null 2>&1  expect fenfa_sshkey.exp ~/.ssh/id_dsa.pub $ip  if [ $? -eq 0 ]  then    action "$ip" /bin/true  else    action "$ip" /bin/false  fidone[oldboy@B .ssh]$ cat fenfa_sshkey.exp#!/usr/bin/expectif { $argc !=2 } {  send_user "usage: expect fenfa_sshkey.exp file host\n"  exit}#define varset file [lindex $argv 0]set host [lindex $argv 1]set password "lrz0412"#spawn scp /etc/hosts root@10.0.0.142:/etc/hosts#spawn scp -P52113 $file oldboy@$host:$dir#spawn ssh-copy-id -i $file "-p 52113 oldboy@$host"spawn ssh-copy-id -i $file "-p 22 oldboy@$host"expect {  "yes/no"    {send "yes\r";exp_continue}  "*password"  {send "$password\r"}}expect eofexit -onexit {  send_user "bye!"}