#!/usr/bin/expect-f

set ip [lindex $argv 0]

set passwd [lindex $argv 1]

set path [lindex $argv 2]

set file [lindex $argv 3]

set cmd [lindex $argv 2]

 

spawn  scp$file password username root@${ip}:$path

expect "password:*"

send "${passwd}\r"

 

spawn /usr/bin/ssh root@${ip}

expect "password:"

send "${passwd}\r"

 

expect "#"

send "chmod +x $path$file\r"

expect "#"

send "$path$file  username password"

expect "#"

send "rm $path$file username password"

expect "#"

send "exit\r"

expect eof

 

 

 

#!/bin/bash

if [ -n "$1" -a -n "$2" ]

then

       if [-e "$1" -a -e "$2" ]

       then

         MAXUSER=`wc -l $1 | cut -d " " -f1`

          MAXPASS=`wc -l $2 | cut -d " " -f 1`

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

       do

         USERNAME= `sed -n ${NUM}p $1`

          PASSWORD= `sed -n ${NUM}p $2`

          CKUSER=`getent passwd $USERNAME`

           [ -z "$CKUSER" ] &&(

           useradd $USERNAME

              echo $PASSWORD |passwd --stdin $USERNAME

          )||echo "$USERNAME Exist !!"

       done

      )||(  echo $1 and $2 havedifferent lines )

elif [ ! -e "$1" ]

   then

   echo"ERROR:$1 is not exsit"

   else

   echo"ERROR:$2 is not exit"

   fi

else

echo "ERROR:Please input userfile and passwordfile after command !!"

fi

 

useradd MAXUSER=`wc -l $1 | cut -d " " -f 1`

passwd MAXPASS=`wc -l $2 | cut -d " " -f 1`