Shell脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 [email protected]$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脚本的主要内容,如果未能解决你的问题,请参考以下文章