expect 密码过期后批量修改
? expect ? ? 过期密码修改 ?    510    0    0

本脚本只是在密码过期后批量修改使用,注意本地系统需要安装expect软件后使用。

sshpasswd.sh 主脚本

#!/usr/bin/expect 
#使用第一个参数 
set server_ip [lindex $argv 0]
set server_user manager
set server_npswd xxxxxxxxx
set server_pswd xxxxxxxx

                                               
# 设置超时时间 
set timeout 5 
spawn ssh  $server_user@$server_ip 
sleep 1
expect { 
    "UNIX password:"
    { 
	  send "$server_pswd\n"; 
    }
}

expect { 
    "New password:"
    { 
	  send "$server_npswd\n";
    } 
}

expect {
    "Retype new password:"
    { 
      send "$server_npswd\n";
# 此命令不退出交互模式
# interact
    }
} 
 
expect eof

change_passwd.sh 循环调用脚本

#!/bin/bash
while read line
do
./sshpaswd.sh ${line}
done < ip_file






觉得不错,点个赞?
Sign in to leave a comment.
No Leanote account ? Sign up now.
0 条评论
文章目录