Linux Bash expect 登录远程主机执行命令
2016-04-26 00:00
288 查看
摘要: centos6.4 expect 远程执行命令
第一篇博客,记录下前几天写的个远程执行命令的脚本,备忘
第一篇博客,记录下前几天写的个远程执行命令的脚本,备忘
#! /bin/bash echo "Hello world" :<<! 远程执行命令 ! declare -r IPADDR="192.168.197.206" declare -r USERNAME="root" declare -r PASSWD="123456" declare -r COMMAND="ls -rlt" function remoteExecCommand(){ local l_username="${1}" local l_ipaddr="${2}" local l_passwd="${3}" local l_cmd="${4}" expect << EOF set timeout 10; spawn ssh ${l_username}@${l_ipaddr}; expect { "\[#$\]" {send "\r" } "password:" {send "${l_passwd}\r"} "(yes/no)?" {send "yes\r";exp_continue} } expect { "\[#$\]" {send "\r" } "Permission" {exit 3 } } expect "\[#$\]";send "${l_cmd}\r"; expect "\[#$\]";send "exit\r"; expect eof; EOF } remoteExecCommand "${USERNAME}" "${IPADDR}" "${PASSWD}" "${COMMAND}"
相关文章推荐
- Linux Shell 01 脚本与变量
- Shell 脚本知识回顾 (二) —— Shell变量
- Shell 脚本知识回顾 (一) —— 基础篇
- Linux下shell颜色配置
- shell编程
- Xshell 4 入门
- linux shell
- Python与shell的3种交互方式介绍
- linux bash shell之declare
- 九.Shell基础
- 51nod1066bash游戏
- python和shell变量互相传递的几种方法
- Bash on Ubuntu on Windows ^_^
- shell命令获取tomcat的进程号id
- linux下Bash函数功能之编写脚本(十一)
- Java调用shell
- AIX下安装bash
- linux-c++调用shell
- shell练习-----猜数值
- Shell函数的简单应用