遠端連線主機,並用檔案匹配方式建立使用者

來源:互聯網
上載者:User

標籤:使用者   password   expect   

#!/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 [email protected]${ip}:$path

expect "password:*"

send "${passwd}\r"

 

spawn /usr/bin/ssh [email protected]${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`

 

 

 


遠端連線主機,並用檔案匹配方式建立使用者

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.