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      


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章