一、将域名取出并根据域名进行计数排序处理
http://www.etiantian.org/index.html
http://www.etiantian.org/1.html
http://post.etiantian.org/index.html
http://mp3.etiantian.org/index.html
http://www.etiantian.org/3.html
http://post.etiantian.org/2.html
几种解答方法:
awk -F "/" '{print $3}' 1.txt | sort -nr | uniq -c
cut -d "/" -f 3 1.txt | sort | uniq -c
cut -d "/" -f 3 1.txt | awk '{++S[$1]} END {for(key in S) print key,S[key]}' | sort -k2
awk -F "/" '{++S[$3]} END {for(key in S) print key,S[key]}' 1.txt | sort -k2
重点:
二、批量分发、部署、管理的十种解决方案介绍
secureCRT的:
三、linux文件系统知识
(太多概念东西 略。。。)
四、expect命令
4.1 expect程序工作流程
expect程序工作流程:
spawn启动进程 --> expect期待关键字 --> send 向进程发送字符 --> 退出结束。
4.2 安装expect
rpm -qa | grep expect
yum install -y expect
4.3 expect 例子
环境:
192.168.26.136 server端
192.168.26.137 client A
192.168.26.138 client B
执行ssh -p22 root@192.168.26.137 /sbin/ifconfig ens33 ,可看到 ② , ③ 是我们会遇到的手动操作步骤。
expect 脚本1
#!/usr/bin/expect
spawn ssh -p22 root@192.168.26.137 /sbin/ifconfig ens33
set timeout 60
expect "*password:"
send "123456\n"
expect eof
exit
执行: 可以看出 不用手动输入密码,就能显示出对方服务器IP信息
expect 1.exp 或 ./1.exp
#注意不能用 bash 1.exp 或 sh 1.exp 否则报错,这里跟shell解释器相关联。
4.4 expect语法
spawn
expect
exp_send 和 send
exp_continue
一般来说,匹配两个内容以上的时候,就用 exp_continue来隔开,否则出问题。
send_user
exit
4.5 expect变量
4.6 expect关键字
eof
timeout
在expect命令中间加上一个小横杠,也可以设置timeout的变量
① 使用expect实现批量分发 /etc/hosts文件
sendHosts.exp
#!/usr/bin/expect
if { $argc != 3 } {
send_user "usage : expect sendHosts.exp file host dir\n"
exit
}
#define var
set file [lindex $argv 0]
set host [lindex $argv 1]
set dir [lindex $argv 2]
set password "123456"
#spawn scp /etc/hosts root@10.0.0.142:/etc/hosts
spawn scp -P22 -p $file root@$host:$dir
set timeout 60
expect {
-timeout 60
"yes/no" {send "yes\r";exp_continue}
"*password" {send "$password\r"}
timeout {puts "expect connect timeout,pls contact xxx"; return}
}
expect eof
exit -onexit {
send_user "bye bye my love...\n"
}
# ./sendHost.exp /etc/hosts 192.168.26.137 /etc/hosts
执行:
./sendHosts.exp /etc/hosts 192.168.26.137 /etc/hosts
./sendHosts.exp /etc/hosts 192.168.26.138 /etc/hosts
批量操作版:
iplist 文本
192.168.26.137
192.168.26.138
fenfa1.sh
#!/bin/sh
. /etc/init.d/functions
for ip in `cat iplist`
do
expect sendHosts.exp /etc/hosts $ip /etc/hosts >/dev/null 2>&1
if [ $? -eq 0 ];then
action "$ip" /bin/true
else
action "$ip" /bin/false
fi
done
② 使用expect实现批量分发ssh秘钥文件
sendSSH.exp
#!/usr/bin/expect
#define var
set file [lindex $argv 0]
set host [lindex $argv 1]
set dir [lindex $argv 2]
set password "123456"
#spawn scp -P22 -r -p /root/.ssh root@192.168.26.137:/root/
spawn scp -P22 -r -p $file root@$host:$dir
set timeout 60
expect {
-timeout 60
"yes/no" {send "yes\r";exp_continue}
"*password" {send "$password\r"}
timeout {puts "expect connect timeout,pls contact xxx"; return}
}
expect eof
# ./sendSSH.exp /root/.ssh 192.168.26.137 /root/
fenfa_sshkey.sh
#!/bin/bash
. /etc/init.d/functions
for ip in `cat iplist`
do
expect sendSSH.exp /root/.ssh $ip /root >/dev/null 2>&1
if [ $? -eq 0];then
action "$ip" /bin/true
else
action "$ip" /bin/false
fi
done
其实这个稍作改造,他能传其他文件/文件夹
./sendSSH.exp /root/shellDir/expectFile 192.168.26.137 /tmp
③ 使用expect实现批量查看客户机的负载内存。
#!/usr/bin/expect
#define var
set host [lindex $argv 0]
set para [lindex $argv 1]
set password "123456"
#ssh -p 22 root@192.168.26.137 'free -m'
spawn ssh -p 22 root@$host "$para"
set timeout 60
expect {
-timeout 60
"yes/no" {send "yes\r";exp_continue}
"*password" {send "$password\r"}
timeout {puts "expect connect timeout,pls contact xxx"; return}
}
expect eof
# ./queryInfo.exp 192.168.26.137 "free -m"
END