#!/usr/bin/expect

set IP [ lindex $argv 0 ]

set PASS [ lindex $argv 1 ]

spawn ssh root@IP

expect {

"yes/no"

{send "yes\r";exp_continue}

"password:"

{send "$PASS\r"}

interact


#!/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

scp /mnt/userfile /mnt/passwdfile root@172.25.254.$NUM &> /dev/null |/mnt/ssh.exp 172.25.254.$NUM

if

[ -e /mnt/userfile -a -e /mnt/passwdfile ]

then

MAXUSER=`wc -l /mnt/userfile | cut -d " " -f 1`

MAXPASS=`wc -l /mnt/passwdfile | cut -d " " -f 1`

[ "$MAXUSER" -EQ "$MAXPASS" ]&&(for NUM in $(seq 1 $MAXUSER)

do

USERNAME=`sed -n ${NUM}p /mnt/userfile`

PASSWORD=`sed -n ${NUM}p /mnt/passwdfile`

CKUSER=`getent passwd class$NUM`

[ -z "$CKUSER" ]&&(

useradd class$NUM

echo $PASSWORD | passwd --stdin class$NUM)||echo "class$MUN exist ")||(echo /mnt/userfile and /mnt/passwdfile have different lines)||(echo 172.25.254.$NUM passwd is error)