首页 > 其他分享 >利用expect交互批量修改普通用户过期密码

利用expect交互批量修改普通用户过期密码

时间:2024-04-25 17:15:21浏览次数:24  
标签:fifofile 过期 ip echo passwd expect 普通用户

因为公司接了一个密码托管的活,有10000多台机器,系统有 openSUSE,SUSE,Ubuntu,centos,Oracle-Linux,

而且什么版本都有,不给root权限,密码已经过期很多,先用expect的方式把过期密码修改完成,在进行托管

#!/bin/bash
#Author:shsnc-****
#Time:2021-5-11
#Name:for_user.sh
#Version:V1.3
#Description:This is a password check  script.


>passwd.info
>passwd.error

old_passwd=$1
new_passwd=$2
user=gziaas

# 定义并发
thread=10
fifofile="/tmp/$$.fifo"
mkfifo $fifofile 
exec 8<>${fifofile}
rm -f ${fifofile}

for pid in `seq ${thread}` 
do 
    echo >&8

done


# 定义修改函数
function change_passwd_ssh(){
 /usr/bin/expect << EOF
       set timeout 20
       spawn /usr/bin/ssh ${user}@$ip
       expect {
           "(yes/no)?" {send "yes\r";exp_continue}
           "*assword:" {send "${old_passwd}\r";}
       }

       expect {
            "(current) UNIX password:" {send "${old_passwd}\r";}
            "Old Password:" {send "${old_passwd}\r";}
       }

       expect {
              "New *assword:" {send "${new_passwd}\r";}
              "Retype new password:" {send "$new_passwd\r";} 
       }

       expect {
              "Retype new password:" {send "$new_passwd\r";}
       }

       expect {
              "Reenter New Password:" {send "$new_passwd\r";}
              "Retype new password:" {send "$new_passwd\r";}
       }


      send "exit\r"
      expect eof

EOF
}

# 脚本主体

for ip in `cat ip_list.txt`
do
    read -u 8
    {
       change_passwd_ssh $1 $2    1>>./passwd.info 2>>./passwd.error
       if [ $? -eq 0 ];then
           echo "${ip}" >>./successful.ip
       else 
           echo "${ip}" >>./fail.ip
       fi
       echo >&8
    }&   
done
wait
exec 8>&-
-----你努力获得的,都是自己的,不容易忘掉。 星辰和大海都需要门票,诗和远方的路费都很贵。来人间一次,努力成为最好的自己。人间值得,未来可期。

标签:fifofile,过期,ip,echo,passwd,expect,普通用户
From: https://www.cnblogs.com/cheyunhua/p/18158116

相关文章

  • 12.prometheus监控之Domain域名过期监控
    一、域名过期时间监控域名的监控通过domain_exporter来完成domain_exporter:https://github.com/caarlos0/domain_exporter/releases二、domain_exporter安装2.1源码安装方法https://prometheus.io/download/wgethttps://github.com/caarlos0/domain_exporter/releases/......
  • 普通用户权限运行docker
    docker安装后默认权限是管理员,在Ubuntu系统中需要使用sudo命令,但是很多时候docker的拉取操作都是写在脚步里面的,因此执行的时候十分的难搞,如果给脚本sudo权限后那么整个的环境路径都会改变,但是不给就需要手动在脚本中找到docker操作并手动加上sudo命令,因此很多时候我们需要给普通......
  • ansible 删除密码过期账户
    hosts[centos-root]192.168.174.129ansible_ssh_port=22192.168.174.130ansible_ssh_port=22192.168.174.131ansible_ssh_port=22AnsibleVault文件创建AnsibleVault文件#ansible-vaultcreatepasswords.ymlNewVaultpassword:#12345......
  • 交互式转化批处理工具 expect
    交互式转化批处理工具expectexpect中相关命令spawn启动新的进程expect从进程接收字符串send用于向进程发送字符串interact允许用户交互exp_continue匹配多个字符串在执行动作后加此命令例一#!/usr/bin/expectspawnscp/tmp/[email protected]:/tmpe......
  • oracle 修改密码不过期
    1.以sysdba身份进入sqlplus模式 2.查看用户密码的有效期设置一般默认的配置文件是DEFAULTSELECT*FROMdba_profilesWHEREprofile='DEFAULT'ANDresource_name='PASSWORD_LIFE_TIME';3.将密码有效期修改成“无限期”ALTERPROFILEDEFAULTLIMITPASSWORD_LIFE_TIM......
  • 轻松实现自动化文件传输——利用expect脚本进行SCP拷贝
    轻松实现自动化文件传输——利用expect脚本进行SCP拷贝原创 脚本家园 脚本家园 2024-04-1906:00 云南 听全文在日常生活和工作中,我们经常需要在不同的服务器或计算机之间传输文件。尤其是系统管理员和开发人员,他们经常需要远程复制文件到其他机器上。这时,我们可以利......
  • json反序列化 JsonConvert.DeserializeObject 报错 One or more errors occurred. (U
    接口返回的字符串肉眼看起来正常,也是标准json,反序列化时候报错,字符串添加了UTF8-BOM头(windows记事本默认编码),可以通过以下代码移除标头//模拟json字符串对象varjsonStr="{}";byte[]buffer=Encoding.UTF8.GetBytes(jsonStr);varsResult=Encoding.UTF8.GetString......
  • Data studio普通用户采用非SSL的方式连接openGauss
    Datastudio普通用户采用非SSL的方式连接openGauss关闭SSL认证由于openGauss默认开启SSL认证,且配置认证较为麻烦,个人开发测试并不需要它。因此关闭openGauss的远程用户登录SSL认证模式。1.找到postgresql.conf。cd/gaussdb/data/openGaussTest1/2.修改postg......
  • electron启动报错The futex facility returned an unexpected error code
    -启动electron时报错(ubuntu-22.04) githubissue地址:https://github.com/electron/electron/issues/24211?spm=a2c6h.12873639.article-detail.9.320d60da4kg611需要在启动命令前加环境变量  DISPLAY=:0start:"cross-envDISPLAY=:0vue-cli-serviceelectron:serve"......
  • npm ERR! errno CERT_HAS_EXPIRED(淘宝镜像证书过期)
    淘宝镜像证书过期npmERR!codeCERT_HAS_EXPIREDnpmERR!errnoCERT_HAS_EXPIREDnpmERR!requesttohttps://registry.npm.taobao.org/echartsfailed,reason:certificatehasexpired SSL证书已过期导致npm命令失败的问题。通常是因为证书过期或不再受信任而引......