远程调用shell脚本文件和远程复制文件

1、安装sshpass

yum install sshpass

2、本地调用远程服务器的shell脚本文件:

sshpass -p sa ssh root@192.168.56.105 -C "/bin/bash" < test.sh

3、从本地复制文件到远程服务器:

  sshpass -p sa scp egova-pub-ex.jar root@192.168.56.105:/egova 
 
shell脚本:调用 bash test.sh 192.168.56.105
#!/bin/bash
remoteIp="$1"
echo "开始复制service-pub-core.jar文件........."
sshpass -p sa scp /egova/lib/test.sh root@$remoteIp:/egova
if [ $? -ne 0 ]; then
    echo "复制service-pub-core.jar文件失败"
else
    echo "复制service-pub-core.jar文件成功"
fi
echo "开始重启service-pub-core服务........."
sshpass -p sa ssh root@$remoteIp "cd /egova; bash test.sh"
if [ $? -ne 0 ]; then
    echo "启动服务失败"
else
    echo "启动服务成功"
fi

 

posted @ 2019-12-02 15:01  zhaoyanhao  阅读(1955)  评论(0编辑  收藏  举报