shell脚本远程连接服务器并执行指定的shell脚本
1.脚本名称demo.sh
#!/bin/bash
yum -y install expect
expect -c "
spawn scp -r /Users/yunshuodeng/Work/mydocker/app/provider/power-dubbo-provider-1.0-SNAPSHOT.jar root@192.168.2.248:$1
expect {
\"*assword\"
{
set timeout 300;
send \"hntx123456\r\";
}
\"yes/no\"
{
send \"yes\r\"; exp_continue;}
}
expect eof"
expect -c "
spawn scp -r /Users/yunshuodeng/Work/mydocker/app/consumer/power-dubbo-consumer-1.0-SNAPSHOT.jar root@192.168.2.248:$1
expect {
\"*assword\"
{
set timeout 300;
send \"hntx123456\r\";
}
\"yes/no\"
{
send \"yes\r\"; exp_continue;}
}
expect eof"
expect -c "
spawn scp -r /Users/yunshuodeng/Work/mydocker/app/consumer/power-dubbo-api-1.0-SNAPSHOT.jar root@192.168.2.248:$1
expect {
\"*assword\"
{
set timeout 300;
send \"hntx123456\r\";
}
\"yes/no\"
{
send \"yes\r\"; exp_continue;}
}
expect eof"
expect -c "
spawn ssh root@192.168.2.248
expect {
\"*assword\"
{
set timeout 300;
send \"密码\r\";
}
\"yes/no\"
{
send \"yes\r\"; exp_continue;
}
}
expect \"*#\"
send \"cd $1\r\"
expect \"*#\"
send \"./$2\r\"
expect \"*#\"
send \"exit\r\"
expect eof"
echo "success"
2.执行shell
./demo.sh /home/demo mymkdir.sh
- Java 连接远程Linux 服务器执行 shell 脚本查看 CPU、内存、硬盘信息
- Java 连接远程Linux 服务器执行 shell 脚本查看 CPU、内存、硬盘信息
- python3 --Paramiko 远程连接服务器,并同时执行多条shell命令
- Ganymed SSH-2 for Java系列7之删除远程服务器上的非空目录(运用执行shell脚本的方式)
- 在远程服务器上执行本地的shell脚本
- 【Jsch】使用SSH协议连接到远程Shell执行脚本
- pexpect练习实例--批量执行远程服务器上的指定脚本
- 在远程服务器上执行本地的shell脚本
- shell脚本连接并重启远程服务器的方法
- Linux与shell脚本编程:远程连接软件CRT与shell脚本相关知识(解释器,vi编辑器,文件权限与执行方法)
- SSH远程连接执行shell脚本
- windows 下 java程序jsch连接远程linux服务器执行shell命令
- 【Telnet】使用Telnet协议连接到远程Shell执行脚本
- Ganymed SSH-2 for Java系列7之删除远程服务器上的非空目录(运用执行shell脚本的方式)
- ssh连接远程主机执行脚本的环境变量问题
- shell scripts登录远程主机执行远程脚本
- 用Telnet连接到远程服务器执行命令的C#程序
- Java实现远程联接服务器执行shell命令
- ssh执行远程服务器脚本 提示php: command not found
- ssh远程到目标机器执行命令shell脚本