博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
expect实现远程主机自动执行命令脚本
阅读量:5302 次
发布时间:2019-06-14

本文共 1467 字,大约阅读时间需要 4 分钟。

 

2014年第一个脚本,哈哈!!! expect实现远程主机自动执行命令脚本: 

#!/usr/bin/expect --if {
[llength $argv] < 4 } { puts "Usage: $argv0 ip user passwd port commands timeout" exit 1 } match_max 600000 set ip [lindex $argv 0] set user [lindex $argv 1] set passwd [lindex $argv 2] set port [lindex $argv 3] set commands [lindex $argv 4] set timeoutflag [lindex $argv 5] set yesnoflag 0 set timeout $timeoutflag for {} { 1} {} { # for is only used to retry when "Interrupted system call" occured spawn /usr/bin/ssh -q -l$user -p$port $ip expect { "assword:" { send "$passwd\r" break; } "yes/no)?" { set yesnoflag 1 send "yes\r" break; } "FATAL" { puts "\nCONNECTERROR: $ip occur FATAL ERROR!!!\n" exit 1 } timeout { puts "\nCONNECTERROR: $ip Logon timeout!!!\n" exit 1 } "No route to host" { puts "\nCONNECTERROR: $ip No route to host!!!\n" exit 1 } "Connection Refused" { puts "\nCONNECTERROR: $ip Connection Refused!!!\n" exit 1 } "Connection refused" { puts "\nCONNECTERROR: $ip Connection Refused!!!\n" exit 1 } "Host key verification failed" { puts "\nCONNECTERROR: $ip Host key verification failed!!!\n" exit 1 } "Illegal host key" { puts "\nCONNECTERROR: $ip Illegal host key!!!\n" exit 1 } "Connection Timed Out" { puts "\nCONNECTERROR: $ip Logon timeout!!!\n" exit 1 } "Interrupted system call" { puts "\n$ip Interrupted system call!!!\n" } } } if { $yesnoflag == 1 } { expect { "assword:" { send "$passwd\r" } "yes/no)?" { set

转载于:https://www.cnblogs.com/L-H-R-X-hehe/p/3825320.html

你可能感兴趣的文章
实用拜占庭容错算法PBFT
查看>>
java b组 小计算器,简单计算器..
查看>>
java的二叉树树一层层输出,Java构造二叉树、树形结构先序遍历、中序遍历、后序遍历...
查看>>
php libevent 定时器,PHP 使用pcntl和libevent实现Timer功能
查看>>
php仿阿里巴巴,php实现的仿阿里巴巴实现同类产品翻页
查看>>
Node 中异常收集与监控
查看>>
七丶Python字典
查看>>
Excel-基本操作
查看>>
面对问题,如何去分析?(分析套路)
查看>>
Excel-逻辑函数
查看>>
面对问题,如何去分析?(日报问题)
查看>>
数据分析-业务知识
查看>>
nodejs vs python
查看>>
poj-1410 Intersection
查看>>
Java多线程基础(一)
查看>>
TCP粘包拆包问题
查看>>
Java中Runnable和Thread的区别
查看>>
SQL Server中利用正则表达式替换字符串
查看>>
POJ 1015 Jury Compromise(双塔dp)
查看>>
论三星输入法的好坏
查看>>