Chinaunix首页 | 论坛 | 博客
  • 博客访问: 288877
  • 博文数量: 81
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 35
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-19 15:16
文章分类

全部博文(81)

文章存档

2021年(1)

2016年(3)

2015年(6)

2014年(6)

2013年(33)

2012年(32)

分类: LINUX

2021-03-01 11:26:02


点击(此处)折叠或打开

  1. #!/usr/bin/expect
  2. #
  3. # This script can be used to login remote server(first parameter) with passwords in LIST and then execute below tasks.
  4. #


  5. set hostname [lindex $argv 0]
  6. set passwords { abc. changeme changeme.0 changeme.1 }
  7. set try 0

  8. if { $argc == 0 } {
  9.         send_error "Please use this command as ./enable_snmp.sh HOSTNAME\n"
  10.         exit
  11.     }

  12. spawn ssh admin@$hostname
  13. expect {
  14. "(yes/no)?*"
  15. {send "yes\r"; exp_continue;}

  16. "*?assword:*"
  17. {
  18. if { $try >= [llength $passwords] } {
  19.         send_error ">>> wrong passwords\n"
  20.         exit 1
  21.     }
  22.     set ind $try
  23.     send [lindex $passwords $try]\r
  24.     incr try
  25.     exp_continue
  26. }

  27. # To fix the screen running servers.
  28. "Enter Screen Name : "
  29. {send "\r"; exp_continue;}

  30. # Normally, after login, prompt likes this "admin@*:~/>: "
  31. "admin@*/>*"
  32. {send "echo '[lindex $passwords $ind]' | su - root -c \"service snmpd restart;\"\r";send exit\r }

  33. # Abnormally, after login, prompt likes this "admin@* #: "
  34. "admin@*#:**"
  35. {send "echo '[lindex $passwords $ind]' | su - root -c \"service avfirewall stop \"\r";send exit\r }

  36. # Abnormally, after login, prompt likes this "[admin@* ~]$ "
  37. "*$*"
  38. {send "echo '[lindex $passwords $ind]' | su - root -c \"service avfirewall stop ;\"\r";send exit\r }

  39. }
  40. interact





===================

#bin/bash
#
#  This script can be used to enable SNMP one by one which in the file_list(first parameter).
#  Then return the results into output log file.
#


OUTPUT_LOG=`pwd`"/snmp_log"
OUTPUT_RESULT=`pwd`"/snmp_result"
HOSTKEY_FILE="/root/.ssh/known_hosts"
HOST_LIST_FILE=$1


if [[ -e $OUTPUT_LOG ]] ; then
    cp -p $OUTPUT_LOG $OUTPUT_LOG`date +%Y%m%d%H%M`
    >$OUTPUT_LOG
fi
if [[ -e $OUTPUT_RESULT ]] ; then
    cp -p $OUTPUT_RESULT $OUTPUT_RESULT`date +%Y%m%d%H%M`
    >$OUTPUT_RESULT
fi
if [[ -e $HOSTKEY_FILE ]] ; then
    cp -p $HOSTKEY_FILE $HOSTKEY_FILE`date +%Y%m%d%H%M`
    >$HOSTKEY_FILE
fi


if [[  $# != 1 ]]; then
    echo "Usage is ./batch_enable_snmp.sh + HOST_LIST_FILE"
    exit;
fi


exec >$OUTPUT_LOG


for i in `cat ${HOST_LIST_FILE}`;
    do
        sleep 1
        /root/enable_snmp_expect.sh $i
        if [[ $? == "0" ]]; then
            echo "Host: $i configured SNMP" >>$OUTPUT_RESULT;
        else
            echo "Host: $i is not configured SNMP" >>$OUTPUT_RESULT;
        fi
    done


阅读(1606) | 评论(0) | 转发(0) |
0

上一篇:根据IP 查询所有域名

下一篇:没有了

给主人留下些什么吧!~~