在远程机器上执行多个命令 [英] Execute multiple commands on remote machine

查看:136
本文介绍了在远程机器上执行多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下命令中,我尝试使用ssh命令并执行多个命令。如果任何命令失败,即如果!command1退出,则如果!command1和!commnd 2退出,那么我可以退出否则执行命令3我如何实现这个

In the following command i am trying to ssh commands and execute the multiple commands.How can i exit if any of the command fails i.e, if !command1 exit then if !command1 and !commnd 2 exit else execute command 3 on the remote machine.How can i achieve this

 ssh login.com "git clone --bare new@login2.com/repo/ /home/usr1/repo/ && \
                cd /home/usr1/repo/info/                               && \
                echo "hello world" > .a.txt"


推荐答案

只要确保您的报价不会冲突: p>

Just make sure your quotes don't conflict:

ssh login.com \
   'git clone --bare new@login2.com/repo/ /home/usr1/repo/ &&
    cd /home/usr1/repo/info/ &&
    echo "hello world" > .a.txt'

这假设你想在服务器上留下a.txt,否则L



This assumes you wanted to leave a.txt on the server, otherwiseL

ssh login.com \
   'git clone --bare new@login2.com/repo/ /home/usr1/repo/ &&
    cd /home/usr1/repo/info/ &&
    echo "hello world"' > .a.txt

这篇关于在远程机器上执行多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆