I'd like to ssh a piece of shell script code into a single ssh command.
As you all know, you could ssh something like this:
ssh user@host "ls -la"
and receive the output of that command being run on that machine. So, let's say I scripted something on the fly via command line like this:
%prompt%>for i in 1 2 3 4 5
> do
> echo "i = $i\n"
> done
i = 1
i = 2
i = 3
i = 4
i = 5
%prompt%>
Is there a way to get this bundled into 1 command via an ssh? If I bring up this quick script via the command history, I get:
for i in 1 2 3 4 5^Jdo^Jecho "i = $i\n"^Jdone
The "^J" won't work. I tried. Is there some character I can use in it's place? I tried \n and \r, but no dice. Just so we're clear, I'm trying to do something like:
ssh user@host "for i in 1 2 3 4 5^Jdo^Jecho "i = $i\n"^Jdone"
Prompt> mkdir test & cp /home/testfile1.txt /test/testfile1.txt
In the above example the CP command will be executed only if the MKDir command was successful
2)
Prompt> mkdir test ; cp /home/testfile1.txt /test/testfile1.txt
In the above example the CP command will be executed REGARDSLESS if the MKDir command was successful or not.
the second one is executed. i have tried that one.
but when trying the same like for i in 1 2 3;do;echo $i;done; is not working.
i don't know why it is not working.
please anyone send the the solution for the above.