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"
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'
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
What you have there will do it — the &&
chaining will mean the next command only runs if the previous succeeded.
$ true && false && echo "here"
$ true && true && echo "here"
here
$