1.
bash -v 检查执行脚本有没有语法错误,这个是预执行
bash -x 查看执行过程,这个是真正执行一遍,不是预执行
2.
命令 i(insert 插入),在当前行前面插入一行 i\
命令 a(append 附加),在当前行后面添加一行 a\
[root@xuegod13 ~]# echo "hello world"|sed 'i\xuegod'
xuegod
hello world
[root@xuegod13 ~]# echo "hello world"|sed 'a\xuegod'
hello world
xuegod
3.
expect无交互式登录
对服务器批量管理
ip地址信息:ip_pass.txt
[root@xuegod13 ~]# vim /root/ip_pass.txt
192.168.31.13 qazzaq
192.168.31.14 qazzaq
执行expect的脚本文档:ssh.exp,注意格式开头要#!/usr/bin/expect 结尾要expect eof。注意第8行的exp_continue用以在找不到yes/no时继续执行下一部分(因为在登录过一次之后,就没有再次输入yes/no那个选项了,就直接提示输入密码)
[root@xuegod13 ~]# vim ssh.exp
#!/usr/bin/expect
set ipaddr [lindex $argv 0]
set password [lindex $argv 1]
set timeout 30
spawn ssh root@$ipaddr
expect {
"yes/no" {send "yes\r";exp_continue}
"password" {send "$password\r"}
}
expect "#"
send "echo haha\r"
send "exit\r"
expect eof
执行脚本
[root@xuegod13 ~]# vim
#!/bin/bash
for ip in `awk '{print $1}' /root/ip_pass.txt`
do
expect /root/ssh.exp $ip `grep $ip /root/ip_pass.txt|awk '{print $2}'`
done
















