Shell 脚本远程批量执行命令
2016-12-13 14:18
651 查看
#! /usr/bin/expect set ip_array 192.168.11. ###### 网段前缀 set username root set timeout 30 #foreach ip {81 82 83 84 86 87 88 89 91 92 93 94 96 97 98 99} { ######IP for {set ip 21} {$ip <= 22} {incr ip} { ###### 大于等于11小于等于50,如果IP有规律可用 spawn ssh -p 22 $username@$ip_array$ip expect { "(yes/no)?" { send "yes\r"; exp_continue } "Password:" { send "password\r" } } expect "*#" send "cp /etc/login.defs /etc/login.defs.bak\r" send "cp /etc/profile /etc/profile.bak\r" send "cp /etc/pam.d/common-password /etc/pam.d/common-password.bak\r" send "sed -i -e '/^PASS_MIN_DAYS/'d /etc/login.defs\r" send "sed -i -e '/^PASS_WARN_AGE/'d /etc/login.defs\r" send "sed -i -e '/^ca\:\:ctrlaltdel/'d /etc/inittab\r" # send "echo "#ca::ctrlaltdel:/sbin/shutdown -t3 -r now" >> /etc/inittab\r" send "echo PASS_MAX_DAYS 90 >> /etc/login.defs\r" send "echo PASS_MIN_DAYS 5 >> /etc/login.defs\r" send "echo PASS_WARN_AGE 7 >> /etc/login.defs\r" send "echo PASS_MIN_LEN 8 >> /etc/login.defs\r" send "echo TMOUT=300 >> /etc/profile\r" send "echo HISTFILESIZE=5 >> /etc/profile\r" send "echo HISTSIZE=5 >> /etc/profile\r" # send "echo umask 027 >> /etc/profile\r" send "echo password required pam_cracklib.so use_authtok minlen=8 ucredit=-1 lcredit=-1 dcredit=-1 ocredit=-1 >> /etc/pam.d/common-password\r" send "echo auth required pam_tally2.so deny=5 onerr=fail no_magic_root unlock_time=300 >> /etc/pam.d/common-password\r" send "echo password sufficient pam_unix.so md5 shadow nullok try_first_pass use_authtok remember=5 >> /etc/pam.d/common-password\r" expect "*#" send "exit\r" } expect eof
相关文章推荐
- linux远程批量执行命令的shell脚本
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- Python脚本远程批量执行命令
- 批量远程执行shell命令工具
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- ssh远程执行命令方法和Shell脚本实例
- 利用python fabric模块写的批量操作远程主机脚本(命令执行,上传、下载文件)
- 远程执行命令和文件分发shell脚本
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- Linux远程执行Shell命令或脚本
- 简易登录,批量执行命令,批量copy文件shell脚本【Linux运维之道之脚本案例】
- 使用shell脚本ssh远程执行命令,使用awk时总是报错
- 很实用的sh脚本,【批量文件替换】【ssh远程命令执行】【统计某一目录下面所有文档总行数】等
- shell脚本实现同时多台远程主机执行命令的代码分享
- 简易登录,批量执行命令,批量copy文件shell脚本【Linux运维之道之脚本案例】 推荐
- Linux远程拷贝&远程执行命令shell脚本
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- 利用shell脚本执行ssh远程另一台主机执行命令并返回命令的结果集
- 利用python的paramiko模块,自定义函数远程批量执行shell命令