expect 交互 之shell执行命令操作
shell 执行命令操作
/usr/bin/expect -c "
proc jiaohu {} {
send_user expect_start
expect {
password {
send ${RemotePasswd}\r;
send_user expect_eof
expect {
\"does not exist\" {
send_user expect_failure
exit
}
password {
send_user expect_failure
exit
}
Password {
send ${RemoteRootPasswd}\r;
send_user expect_eof
expect {
incorrect {
send_user expect_failure
exit
}
eof
}
}
eof
}
}
passphrase {
send ${KeyPasswd}\r;
send_user expect_eof
expect {
\"does not exist\" {
send_user expect_failure
exit
}
passphrase{
send_user expect_failure
exit
}
Password {
send ${RemoteRootPasswd}\r;
send_user expect_eof
expect {
incorrect {
send_user expect_failure
exit
}
eof
}
}
eof
}
}
Password {
send ${RemoteRootPasswd}\r;
send_user expect_eof
expect {
incorrect {
send_user expect_failure
exit
}
eof
}
}
\"No route to host\" {
send_user expect_failure
exit
}
\"Invalid argument\" {
send_user expect_failure
exit
}
\"Connection refused\" {
send_user expect_failure
exit
}
\"does not exist\" {
send_user expect_failure
exit
} \"Connection timed out\" {
send_user expect_failure
exit
}
timeout {
send_user expect_failure
exit
}
eof
}
}
set timeout $TimeOut
switch $ {
Ssh_Cmd {
spawn ssh -t -p $Port -o StrictHostKeyChecking=no $RemoteUser@$Ip /bin/su - root -c \\\"$Cmd\\\"
jiaohu
}
Ssh_Script {
spawn scp -P $Port -o StrictHostKeyChecking=no $ScriptPath $RemoteUser@$Ip:/tmp/${ScriptPath##*/};
jiaohu
spawn ssh -t -p $Port -o StrictHostKeyChecking=no $RemoteUser@$Ip /bin/su - root -c \\\"/bin/sh /tmp/${ScriptPath##*/}\\\" ;
jiaohu
}
Scp_File {
spawn scp -P $Port -o StrictHostKeyChecking=no -r $ScpPath $RemoteUser@$Ip:${ScpRemotePath};
jiaohu
}
}
"
state=`echo $?`
expect 交互 之shell执行命令操作的更多相关文章
- Shell脚本中实现切换用户并执行命令操作【转】
第一种方法 cat test.sh #!/bin/bashsu - test <<EOFpwd;exit;EOF 执行结果图: 第二种方法 当然也可以用下面的命令来执行 复制代码代码如下: ...
- shell执行mysql操作
http://ully.iteye.com/blog/1226494 http://www.jb51.net/article/55207.htm shell执行mysql操作 mysql -hhos ...
- expect实现远程主机自动执行命令脚本
2014年第一个脚本,哈哈!!! expect实现远程主机自动执行命令脚本: #!/usr/bin/expect -- if { [llength $argv] < 4 } { puts &qu ...
- Linux之执行命令操作20170330
介绍一下Linux系统中的代码执行shell等命令的几种操作方式: 一.标准流管道popen 该函数的原型是FILE * popen(const char* command, const char * ...
- 使用PsExec获取shell执行命令
PsExec PsExec是pstools工具组套件的一部分,确成为了渗透利器,下载地址:点击这里下载 连接shell 我的Windows Server 2012默认打开域网络防火墙的时候,是不能连接 ...
- Scrapy 常用的shell执行命令
1.在任意系统下,可以使用 pip 安装 Scrapy pip install scrapy/ 确认安装成功 >>> import scrapy >>> scrap ...
- linux shell 执行命令顺序
1.shell命令搜索顺序 在linux shell 中输入一个命令,如果有多个同名指令,shell需要按照一定规则去取优先级高的一个执行,shell命令的搜索顺序为: 1.别名,使用alias创建的 ...
- 【转】Shell执行MySql操作
mysql -hhostname -Pport -uusername -ppassword -e 相关mysql的sql语句,不用在mysql的提示符下运行mysql,即可以在shell中操作m ...
- ZooKeeper学习笔记(四)——shell客户端命令操作
ZooKeeper客户端命令行操作 启动服务端 [simon@hadoop102 zookeeper-3.4.10]$ bin/zkServer.sh start 查看状态信息 Using confi ...
随机推荐
- 为什么说LAXCUS颠覆了我的大数据使用体验
切入正题前,先做个自我介绍. 本人是从业三年的大数据小码农一枚,在帝都一家有点名气的广告公司工作,同时兼着大数据管理员的职责. 平时主要的工作是配合业务部门,做各种广告大数据计算分析工作,然后制成各种 ...
- 第二个spring冲刺第8天
今天我们团队分别安排了不同的任务,分别是1人程序编写,1人检查bug,1人负责客户体验,还有我们的总负责人王俊凯同学负责各个部分的协调.今天程序有了新的调整,但是功能还是没有完全做出来,不过还在开发途 ...
- 基于RYU restful api实现的VLAN网络虚拟化
基于RYU restful api实现的VLAN网络虚拟化 前言 本次实验是基于OVS的VLAN虚拟化简易实践方案的进一步的实验,采用RYU restful api进行配置.本质上和上次实验没什么差, ...
- Visual Studio 2015的安装和简单的测试
首先是Visual Studio 2015的安装 Visual Studio是微软开发的一套基于组件的软件开发工具,目前最新的版本是2015. 在 I Tell you 网站下载Visual Stud ...
- JwtUtils 工具类
/** * jwt工具类 */ public class JwtUtils { public static final String SUBJECT = "onehee"; *** ...
- Python进阶-字符串格式化
目录 前言 %格式化 str.format() f-Strings 特殊符号处理 前言 在 Python 3.6 之前,字符串格式化方法主要有两种: %格式化 str.format() 在Python ...
- Graph Database & 图形数据库
Graph Database 图形数据库 https://en.wikipedia.org/wiki/Graph_database cayley https://github.com/cayleygr ...
- 淘宝卖家搜索器V1.6算法注册机。
该软件的算法非常简单,适合小白练手.(E语言写的)1.OD加载该软件,输入bp MessageBoxA 2.点击注册 3.OD就会中断下来了 4.按ALT+K打开调用堆栈 5.往上翻,就来到算法处了 ...
- 【跨域】jsonp跨域实现方法
封装原生jsonp: 以跨域调取豆瓣电影最热榜单为例: function $jsonp(url,data,callback){ var funcName = 'jsonp_cb' + Math.ran ...
- CUDA ---- device管理
device管理 NVIDIA提供了集中凡是来查询和管理GPU device,掌握GPU信息查询很重要,因为这可以帮助你设置kernel的执行配置. 本博文将主要介绍下面两方面内容: CUDA run ...