• 利用expect远程控制相关脚本


    exe_start_agent.sh

    #!/bin/sh

    FILENAME="ip.file"
    cat $FILENAME|while read line
    do
    eval `echo $line|awk '{print "IP="$1}'`
    eval `echo $line|awk '{print "USER="$2}'`
    eval `echo $line|awk '{print "PATHWORD="$3}'`
    echo "$IP $USER $PATHWORD"

    ./start_agent.exp $IP $USER $PATHWORD
    echo "start succuss"
    done

    exe_stop_agent.sh

    #!/bin/sh

    FILENAME="ip.file"
    cat $FILENAME|while read line
    do
    echo $line
    eval `echo $line|awk '{print "IP="$1}'`
    eval `echo $line|awk '{print "USER="$2}'`
    eval `echo $line|awk '{print "PATHWORD="$3}'`
    echo "$IP $USER $PATHWORD"

    ./scp.exp $IP $USER $PATHWORD
    echo "scp success"
    sleep 1
    ./ssh.exp $IP $USER $PATHWORD
    echo "ssh success"
    done 

    ip.file

    127.0.0.1 user password

    scp.exp

    #!/usr/bin/expect -f

    set timeout 300
    set ip [lindex $argv 0]
    set user [lindex $argv 1]
    set password [lindex $argv 2]

    spawn scp stop_agent.sh ${user}@${ip}:stop_agent.sh

    expect {
    "*yes/no*" { send "yes "; exp_continue}
    "*password:" { send "$password " }
    }
    expect "*password:"

    send "$password "

    send "exit "

    expect eof

    ssh.exp

    #!/usr/bin/expect -f

    set timeout 30
    set ip [lindex $argv 0]
    set user [lindex $argv 1]
    set password [lindex $argv 2]


    spawn ssh ${user}@${ip}
    expect {
    "yes/no" { send "yes "; exp_continue}
    "*password:" { send "$password " }
    }

    expect {
    "*$*" {
    send "sh stop_agent.sh "
    expect "*$*"
    send "rm stop_agent.sh "
    expect "*$*"
    send "exit "
    }
    "*>*" {
    send "sh stop_agent.sh "
    expect "*>*"
    send "rm stop_agent.sh "
    expect "*>*"
    send "exit "
    }
    }

    expect eof

    start_agent.exp

    #!/usr/bin/expect -f

    set timeout 30
    set ip [lindex $argv 0]
    set user [lindex $argv 1]
    set password [lindex $argv 2]


    spawn ssh ${user}@${ip}
    expect {
    "yes/no" { send "yes "; exp_continue}
    "*password:" { send "$password " }
    }

    expect {
    "*$*" {
    send "sh ~/agent/bin/agent_monitor.sh ~/agent/bin "
    expect "*$*"
    send "exit "
    }
    "*>*" {
    send "sh ~/agent/bin/agent_monitor.sh ~/agent/bin "
    expect "*>*"
    send "exit "
    }
    }

    expect eof

    stop_bocs.sh

    #!/bin/sh

    cd agent/bin
    echo "begin"
    crontab_bocs=`crontab -l |grep -w "agent" |grep -w "agent_monitor.sh"|grep -v grep |wc -l`
    if [ "${crontab_bocs}" != "0" ]
    then
    crontab -l > crontab_bocs.list
    sed '/agent/bin/agent_monitor.sh/'d crontab_bocs.list >list.list
    crontab list.list
    rm crontab_bocs.list
    rm list.list
    fi
    sh stop.sh
    rm ../output/*
    echo "end"

  • 相关阅读:
    设计模式之适配器模式(Adapter)
    数组中的趣味题(二)
    VSTS 2008 自定义签入代码审查策略
    自定义 Vista 系统下程序运行级别
    全国省份,城市,地区全数据(SQL版与XML版)包括各城市邮编
    LINQ 从数据库读数据生成 XML
    IE 8 Beta 2 初体验 隐藏了的"IE7模式"
    利用宏帮助快速录入代码
    你现在的生活是你n年前决定的
    控制参数个数的几种方式
  • 原文地址:https://www.cnblogs.com/wcc331902579/p/5923058.html
Copyright © 2020-2023  润新知