1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#!/bin/bash read -p "Please input the operation (create or delete ): " OPERATION case $OPERATION in create) // El primer caso: crear read -p "Please input the userfile : " USERFILE [ -e $USERFILE ] || { echo "$USERFILE is not exist " exit 1 } read -p "Please input the passwdfile : " PASSFILE [ -e $PASSFILE ] || { echo "$PASSFILE is not exist " exit 1 } USERLINE=`awk 'BEGIN{N=0}{N++}END{print N}' $USERFILE` for LINE_NUM in `seq 1 $USERLINE` do USERNAME=`sed -n "${LINE_NUM}p" $USERFILE` PASSWORD=`sed -n "${LINE_NUM}p" $PASSFILE` useradd $USERNAME echo $PASSWORD | passwd --stdin $USERNAME done ;; delete) read -p "Please input the userfile : " USERFILE [ -e $USERFILE ] || { echo "$USERFILE is not exist " exit 1 } USERLINE=`awk 'BEGIN{N=0}{N++}END{print N}' $USERFILE` for LINE_NUM in `seq 1 $USERLINE` do USERNAME=`sed -n "${LINE_NUM}p" $USERFILE` userdel -r $USERNAME done ;; *) echo Error! ;; Esac |
1 2 3 4 5 6 7 8 9 |
#!/bin/bash /usr/bin/expect << EOF spawn ssh root@$1 expect { "yes/no" { send "yes\r";exp_continue } "password" { send "$2\r" } } Interact EOF |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#!/bin/bash Auto_Connect() { /usr/bin/expect << EOF set timeout 5 spawn ssh root@172.25.254.$IP_NUM hostname expect { "yes/no" { send "yes\r";exp_continue } "password:" { send "westos\r" } } expect eof EOF } for IP_NUM in {71..72} do ping -c1 -w1 172.25.254.$IP_NUM &> /dev/null && { Host_Name=`Auto_Connect | grep -E "authenticity|fingerprint|connecting|password|spawn|Warning" -v` } echo " $Host_Name 172.25.254.$IP_NUM" done |
1 2 3 4 5 6 7 8 9 |
#!/bin/bash /usr/bin/expect << EOF spawn ssh root@$1 expect { "yes/no" { send "yes\r";exp_continue } "password" { send "$2\r" } } Interact EOF |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#!/bin/bash Auto_Connect() { /usr/bin/expect << EOF set timeout 5 spawn ssh root@172.25.254.$IP_NUM hostname expect { yes/no { send "yes\r";exp_continue } password { send "redhat\r" } } expect eof EOF } for IP_NUM in {226..227} do ping -c1 -w1 172.25.254.$IP_NUM &> /dev/null && { Host_Name=`Auto_Connect | grep -E "authenticity|fingerprint|connecting|password|spawn|Warning" -v` } echo "$Host_Name 172.25.254.$IP_NUM " | sed 's/\r//g' Done |