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 ...
随机推荐
- 通过监控Nginx日志来实时屏蔽高频恶意访问的IP
目前在我的VPS上主要通过两种方式来限制ip的访问次数. 通过Nginx的limit_req配置来限制同一ip在一分钟内的访问次数 通过Nginx deny封禁一天内超过指定次数的ip(需要一个监控脚 ...
- 微软职位内部推荐-Senior Program Manager
微软近期Open的职位: Title: Senior Program Manager – Bing Multimedia Relevance Group: Search Technology Cent ...
- 《Linux内核分析》 第一节 计算机是如何工作的
第一节 计算机是如何工作的 张嘉琪 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-100002900 ...
- 作业三:LINUX内核的启动过程
作业三:LINUX内核的启动过程 一.使用GDB跟踪内核从start_kernel到init进程启动(附实验截图) (一)使用自己的Linux系统环境搭建MenuOS的过程 下载内核源代码编译内核 c ...
- Answer My Questions
回答自己的问题,真棒!断电让自己的工作重来.真棒! 阅读以前自己的博客,发现问题都已经有了答案. (1).想要成为一名专业的软件工程师,首先得是有相关的资格证书,这个可以通过软考获得.然后在职场中锻炼 ...
- Spherical Hashing,球哈希
1. Introduction 在传统的LSH.SSH.PCA-ITQ等哈希算法中,本质都是利用超平面对数据点进行划分,但是在D维空间中,至少需要D+1个超平面才能形成一个封闭.紧凑的区域.而球哈希方 ...
- RYU 灭龙战 fourth day (2)
RYU 灭龙战 fourth day (2) 前言 之前试过在ODL调用他们的rest api,一直想自己写一个基于ODL的rest api,结果还是无果而终.这个小目标却在RYU身上实现了.今日说法 ...
- BAE静态文件问题
这几天想在bae上架一个自己的博客,但是老是访问不到静态文件文件,都要没有办法了,最后看了这篇博客,受到了启发,知道了问题所在: 我自己的原始的app.conf的配置如下: handlers: - u ...
- 使用Samba服务程序,让linux系统之间共享文件
yum install -y cifs-utils mkdir /database 创建挂载目录 在root家目录创建认证文件(依次为SMB用户名.SMB用户密码.SMB共享域) v ...
- bower安装和使用
bower的安装 1,首先在我的系统 安装 nodejs.因为我的系统是windows,还需要安装msysgit,注意图二中的选项 msysgit Git setup 2,之后就可以用npm包 ...