1.ssh 報錯
reverse mapping checking getaddrinfo for bogon [IP地址] failed - POSSIBLE BREAK-IN ATTEMPT!
解決方法:
解決方法一:在/etc/hosts 文件加上遠程主機名和 ip地址
解決方法二:/etc/ssh/ssh_config 修改這個配置文件
GSSAPIAuthentication yes 改成 GSSAPIAuthentication no
建議採用第一種。第一種不好使再用第二種
2.CTRL +R 反向查找命令
ESC:將命令查找到終端上,但是不執行。
再按CTRL +R :繼續往後查找命令。
ENTER :執行命令
3.expect與bash的交互
由於公司需要批量改密碼,本想用ansible的,但是安裝ansible有點麻煩,就用了expect,記錄一下測試代碼:
#!/bin/bash auto_login() { expect -c " spawn ssh $user_name@$ip_addr expect { \"*(yes/no)?\" {send \"yes\r\" ; exp_continue} \"*password:\" {send \"$user_pwd\r\" ; exp_continue} } " } auto_sudo() { expect -c " spawn sudo -i expect { \"*codis:\" {send \"$sudo_pwd\" ; exp_continue} } " } cat /tmp/expect/ip_user.txt |while read user_name ip_addr user_pwd sudo_pwd do auto_login && echo "login codis sucessuful" || echo "logini failed" auto_sudo sed -i '/user=/c user=root' /etc/my.cnf done
4.