批量登陆linux主机脚本

#test.sh
  #!/bin/bash
  dir = /home/test
  while  read  line
  do
  host=` echo  $line|  awk  '{print $1}' `
  passwd =` echo  $line |  awk  '{print $2}' `
  $ dir /expect_ssh .sh $host $ passwd  &
  done  < $ dir /host .txt
 
  #expect_ssh.sh
  #!/usr/bin/env expect
  set  HOST [lindex $argv 0]
  set  PASSWD [lindex $argv 1]
  spawn  ssh  root@$HOST
  expect   "(yes/no)?"  { send  "yes\n"  }
  expect  "*password:"  { send  "$PASSWD\n"  }
  expect  "*password:"  { send  "$PASSWD\n"  }
  expect  "*#"  { send  "useradd -u 0 -g 0 username\n"  } #执行相关操作,比如adduser
  expect eof
  #host.txt格式,可从数据库中导出
IP            passwd