首页 > 代码库 > Shell脚本

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脚本