#! /usr/bin/expect ip_array = $(cat /tmp/ip.txt) username = root for ip in ${ip_array[*]} { ######IP spawn ssh -p 6122 $username@$$ip expect { "(yes/no)?" { send "yes\r"; exp_continue } "Password:" { send "p@ssw0rdWAS\r" } ###### root密码 } 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_MAX_DAYS/‘d /etc/login.defs\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 "cecho 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 "secho PASS_MIN_LEN 8 >> /etc/login.defs\r" send "echo TMOUT=300 >> /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" expect "*#" send "exit\r" } expect eof
本文出自 “汜水流年_” 博客,请务必保留此出处http://timefiles.blog.51cto.com/8475652/1882242
原文地址:http://timefiles.blog.51cto.com/8475652/1882242