expect免互交 常用编辑文本


expect免互交

yum -y install expect

cat ip_pass.txt #这里写上要执行的IP地址和root用户密码
192.168.1.63 123456
192.168.1.63 123456
192.168.1.63 123456
cat ssh2.exp #编写要执行的操作
#!/usr/bin/expect

set ipaddr [lindex $argv 0]
set passwd [lindex $argv 1]
set timeout 30
spawn ssh [email protected]$ipaddr
expect {
"yes/no" { send "yes\r";exp_continue }
"password" { send "$passwd\r" }
}

expect "#"
send "touch /root/xuegod1011.txt\r"
send "ls /etc > /root/xuegod1011.txt\r"
send "mkdir /tmp/xuegod1011\r"
send "exit\r"
expect eof
cat login.sh #开始执行
#!/bin/bash
echo
for ip in `awk {print $1} /root/ip_pass.txt`
do
pass=`grep $ip /root/ip_pass.txt|awk {print $2}`
expect /root/ssh.exp $ip $pass
done

 

统计/etc/ssh/sshd_config文件中除去空行和#号开头的行的行数
egrep -v "^$|^#" /etc/ssh/sshd_config


sed -i ‘s/root/xuegod/‘ /etc/passwd

sed -i ‘s/IPADDR=192.168.1.63/IPADDR=192.168.1.65/‘ /etc/sysconfig/network-scripts/ifcfg-ens33

cut -f1 -d ":" /etc/passwd

date | md5sum | cut -c1-6

bash -v test.bash #查看bash是否存在语法错误bash -x test.bash #查看bash详细的执行过程

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...