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执行命令操作的更多相关文章

  1. Shell脚本中实现切换用户并执行命令操作【转】

    第一种方法 cat test.sh #!/bin/bashsu - test <<EOFpwd;exit;EOF 执行结果图: 第二种方法 当然也可以用下面的命令来执行 复制代码代码如下: ...

  2. shell执行mysql操作

    http://ully.iteye.com/blog/1226494 http://www.jb51.net/article/55207.htm shell执行mysql操作 mysql  -hhos ...

  3. expect实现远程主机自动执行命令脚本

    2014年第一个脚本,哈哈!!! expect实现远程主机自动执行命令脚本: #!/usr/bin/expect -- if { [llength $argv] < 4 } { puts &qu ...

  4. Linux之执行命令操作20170330

    介绍一下Linux系统中的代码执行shell等命令的几种操作方式: 一.标准流管道popen 该函数的原型是FILE * popen(const char* command, const char * ...

  5. 使用PsExec获取shell执行命令

    PsExec PsExec是pstools工具组套件的一部分,确成为了渗透利器,下载地址:点击这里下载 连接shell 我的Windows Server 2012默认打开域网络防火墙的时候,是不能连接 ...

  6. Scrapy 常用的shell执行命令

    1.在任意系统下,可以使用 pip 安装 Scrapy pip install scrapy/ 确认安装成功 >>> import scrapy >>> scrap ...

  7. linux shell 执行命令顺序

    1.shell命令搜索顺序 在linux shell 中输入一个命令,如果有多个同名指令,shell需要按照一定规则去取优先级高的一个执行,shell命令的搜索顺序为: 1.别名,使用alias创建的 ...

  8. 【转】Shell执行MySql操作

    mysql  -hhostname -Pport -uusername -ppassword  -e  相关mysql的sql语句,不用在mysql的提示符下运行mysql,即可以在shell中操作m ...

  9. ZooKeeper学习笔记(四)——shell客户端命令操作

    ZooKeeper客户端命令行操作 启动服务端 [simon@hadoop102 zookeeper-3.4.10]$ bin/zkServer.sh start 查看状态信息 Using confi ...

随机推荐

  1. YQCB冲刺第二周第六天

    今天的任务为界面的美化. 昨天的任务为实现由用户设置每月初始额度的功能. 暂未遇到问题. 站立会议 任务面板

  2. 毕业设计---jQuery动态生成的a标签的事件绑定

    这几天在毕业设计的前端设计阶段,准备放弃使用jsp,完全通过html+ajax+SSH进行网站的编写,在前端的页面显示我准备使用jQuery来实现数据的动态绑定.但是遇到动态添加的a标签无法直接通过$ ...

  3. 设置macbook休眠模式

    前言: macbook默认合上盖默认是进入混合休眠模式模式(mode 3),此时电脑还会供电.不想耗电的话关机的话当前的工作状态就丢失了. macbook实际上是可以进入休眠模式的,只是没开放出来,我 ...

  4. idea不能跟随输入法问题

    在写注释的时候会发现输入法不跟随,这是idea工具本身存在的bug,这个问题很头疼,我找了好多办法都不行,比如删除idea自带的jre,这个办法对我的2018.1.5版本并不适用,以下办法是不需要删除 ...

  5. meta-inf文件夹以及MANIFEST.MF文件的作用

    meta-inf相当于一个信息包,目录中的文件和目录获得Java 2平台的认可与解释,用来配置应用程序.扩展程序.类加载器和服务 manifest.mf文件,在用jar打包时自动生成的. META-I ...

  6. Only IPV6 下 使用MSDTC ping 之后 出现 找不到主机的问题

    1. 很奇怪 使用两个虚拟机 进行IPV6测试, 需要验证MSDTC. app的机器名 Win12r2update DB的机器名 Win12r2UpdateDB 2. 在使用ipv4 以及 不进行ho ...

  7. [转帖]SSL/TLS/WTLS原理

    SSL/TLS/WTLS原理 作者:yawl < yawl@nsfocus.com >主页:http://www.nsfocus.com日期:2001-02-19 一 前言 首先要澄清一下 ...

  8. 详细理解servlet实现的三种方式和生命周期

    阅读目录 开发servlet的三种方式 理解实现servlet接口的方式,理解servlet生命周期 Servlet接口有五个方法 继承GenericServlet 继承HttpServlet 现在很 ...

  9. 【刷题】BZOJ 3512 DZY Loves Math IV

    Description 给定n,m,求 模10^9+7的值. Input 仅一行,两个整数n,m. Output 仅一行答案. Sample Input 100000 1000000000 Sampl ...

  10. 自学Zabbix3.10.1.5-事件通知Notifications upon events-媒介类型Script

    点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix3.10.1.5-事件通知Notifications upon events-媒介 ...