expect kullanarak bash’te toplu şifre değiştirme

Diyelim ki 10 tane kullanıcınız var basit bir döngü ile kullanıcıların şifrelerini değiştirmek istiyorsunuz. Expect kullanarak aşağıdaki gibi değiştirebilirsiniz.

#!/bin/bash
#Cem DOGAN - 11.07.2012 - expect ornegi

for c in `seq 1 10`
do

UNAME=kullaniciadi$c
PASS=sifresi$c
#gerekirse kullanici da eklenebilir
#useradd -s /sbin/nologin $UNAME

expect << EOF
spawn passwd $UNAME
expect "New UNIX password:"
send "${PASS}r"
expect "Retype New UNIX password:"
send "${PASS}r"
expect eof;
EOF

done

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.