Chinaunix首页 | 论坛 | 博客
  • 博客访问: 123443
  • 博文数量: 11
  • 博客积分: 880
  • 博客等级: 准尉
  • 技术积分: 410
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-13 09:30
文章分类

全部博文(11)

文章存档

2011年(2)

2008年(9)

我的朋友

分类: LINUX

2011-10-13 10:11:59

#!/bin/bash

cd ~

echo $(date) start > rootpw_history

# Assume all servers are put in PROD.list
if [ -e PROD.list ]
then

USER=user
PASSWD=pass

cat PROD.list |while read HOST
do

TOKEN=$(mkpasswd -l 10 -s 0)
echo $HOST "$TOKEN" >> rootpw_history

# To avoid password exposed via ps output, this is the way to hide sensitive info.
expect <debug
log_file ~/rootpw_history
spawn ssh -l $USER $HOST

expect {
 "yes/no" { send "yes\r"; exp_continue }
 "*assword:" { send "$PASSWD\r" }
}

expect "*~]$"
send "sudo passwd \r"
expect "*assword*:"
send "$PASSWD\r"
expect "*UNIX password:"
send "$TOKEN\r"
expect "*new UNIX password:"
send "$TOKEN\r"
expect "*~]$"
send "exit \r"

EOF

echo $HOST done >> rootpw_history

done

else

echo No PROD.list found >> rootpw_history
fi

echo $(date) end >> rootpw_history


阅读(2335) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~