车皮 发表于 2018-8-21 11:37:42

作业shell-12115084

  # vim ssh.exp
  #!/usr/bin/expect
  set timeout 2
  set IP [ lindex $argv 0 ]
  set PASS [ lindex $argv 1 ]
  set COMM [ lindex $argv 2 ]
  spawn ssh root@$IP $COMM
  expect {
  "yes/no"
  {send "yes\r";exp_continue}
  "password:"
  {send "$PASS\r"}
  {send "$COMM\r"}
  }
  expect eof
  # vim create_user.sh
  #!/bin/bash
  for NUM in {1..33}
  do
  ping -c1 -w1 172.25.254.$NUM &> /dev/null && (
  /mnt/ssh.exp 172.25.254.$NUM redhat &> /dev/null
  done
  if
  [ -n "$1" -a -n "$2" ]
  then
  if
  [ -e "$1" -a -e "$2" ]
  then
  MAXUSER=`wc -l $1 | cut -d " " -f 1`
  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 have different lines
  )
  elif
  [ ! -e "$1" ]
  then
  echo "ERROR:$1 is not exsit"
  else
  echo "ERROR:$2 is not exsit"
  fi
  else
  echo "ERROR: Please input userfile and password file after command !!"
  fi

页: [1]
查看完整版本: 作业shell-12115084