1
2
3
4
5
|
# cat old_info
# ip user passwd port
#------------------------------------------------
192.168.18.217 root 123456 22
192.168.18.218 root 123456 22
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# cat change_pass.sh
#!/bin/bash
OLD_INFO=~
/old_info
NEW_INFO=~
/new_info
for
IP
in
`
awk
'/^[^#]/{print $1}'
$OLD_INFO`;
do
USER=`
awk
-
v
I=$IP
'{if(I==$1)print $2}'
$OLD_INFO`
PASS=`
awk
-
v
I=$IP
'{if(I==$1)print $3}'
$OLD_INFO`
PORT=`
awk
-
v
I=$IP
'{if(I==$1)print $4}'
$OLD_INFO`
NEW_PASS=`mkpasswd -l 8`
echo
"$IP $USER $NEW_PASS $PORT"
>> $NEW_INFO
expect -c "
spawn
ssh
-p$PORT $USER@$IP
set
timeout 2
expect {
\"(
yes
/no
)\" {send \"
yes
\r\";exp_continue}
\"password:\" {send \"$PASS\r\";exp_continue}
\"$USER@*\" {send \"
echo
\'$NEW_PASS\' |
passwd
--stdin $USER\r
exit
\r\";exp_continue}
#\"$USER@*\" {send \"df -h\r exit\r\";exp_continue}
}"
done
|
1
2
3
|
# cat new_info
192.168.18.217 root n8wX3mU% 22
192.168.18.218 root c87;ZnnL 22
|