码迷,mamicode.com
首页 > 系统相关 > 详细

Shell脚本

时间:2016-12-17 23:23:48      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:shell脚本

shell脚本:

将172.25.254.1-10的主机一一检查是否开启,开启的话通过ssh连接,并将/mnt/create/下的userfile和passwood中的用户建立,并修改好密码


/mnt/test_useradd.sh

#!/bin/bash

MAX#!/bin/bash

MAX=10

max=$( wc -l /mnt/create/userfile | cut -d " " -f 1 )

for NUM in $( seq 1 $MAX )

IP=172.25.254.$NUM

do

        for num in $( seq 1 $max )

        do

        ping -c1 -w1 $IP &> /dev/null && (

        /mnt/.ssh.exp $IP redhat hostname | grep -E "^The|ECDSA|connecting|Warning|password|spawn" -v && (

        USERNAME=$( sed -n ${num}p /mnt/create/userfile )

        PASSWD=$(sed -n ${num}p /mnt/create/password )

        useradd $USERNAME

        echo $PASSWD | passwd --stdin $USERNAME

        ))

        done

done

=10

max=$( wc -l /mnt/create/userfile | cut -d " " -f 1 )

for NUM in $( seq 1 $MAX )

IP=172.25.254.$NUM

do

        for num in $( seq 1 $max )

        do

        ping -c1 -w1 $IP &> /dev/null && (

        /mnt/.ssh.exp $IP redhat hostname | grep -E "^The|ECDSA|connecting|Warning|password|spawn" -v && (

        USERNAME=$( sed -n ${num}p /mnt/create/userfile )

        PASSWD=$(sed -n ${num}p /mnt/create/password )

        useradd $USERNAME

        echo $PASSWD | passwd --stdin $USERNAME

        ))

        done

done

 

 

/mnt/.ssh.exp

#!/usr/bin/expect

set timeout 3

set IP [lindex $argv 0]

set PASS [lindex $argv 1]

set COMM [lindex $argv 2]

spawn ssh root@$IP $COMM

expect {

        "yes/no"

        {send "yes\r";exp_continue}

        "password:"

        {send "$PASS\r"}

        }

expect eof

 

 

/mnt/create/userfile

tbr1

tbr2

tbr3

    

 

/mnt/create/password      

123

123

123      


Shell脚本

标签:shell脚本

原文地址:http://10664148.blog.51cto.com/10654148/1883641

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