码迷,mamicode.com
首页 > 其他好文 > 详细

ping前十台主机并建立用户

时间:2016-12-16 01:52:53      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:password   expect   please   error   null   

#!/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前十台主机并建立用户

标签:password   expect   please   error   null   

原文地址:http://12110661.blog.51cto.com/12100661/1883196

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!