首页 > 代码库 > ping前十台主机并建立用户

ping前十台主机并建立用户

#!/usr/bin/expect
#!/bin/bash
for NUM in {1..10}
do
ping -c1 -w1 172.25.254.$NUM &> /dev/null && (
        /mnt/ssh.exp 172.25.254.$NUM redhat hostname | grep -E "^The|ECDSA|connecting|Warning|password|spawn" -v|sed "s/Permission\ denied\,\ please\ try\ again\./172.25.254.$NUM password is error/g"
)
        set IPADDR [ lindex $argv 0 ]
        set PASS   [ lindex $argv 1 ]

        spawn ssh root@$IPADDR
        expect {
                "yes/no"
                {send "yes\r";exp_continue}
                "password:"
                {send "$PASS\r"}
                }
        interact
        MAX=$( wc -l $1 | cut -d " " -f 1)

        for NUM in $( seq $MAX )

        do
            USERNAME=$( sed -n ${NUM}p $1)
            PASSWD=$( sed -n ${NUM}p $2)
            useradd $USERNAME
            echo $PASSWD | passwd --stdin $USERNAME
        done
done

ping前十台主机并建立用户