I am performing some interactive testing using HP's QuickTest Professional and Linux. I am connecting via SSH and feeding the BASH script lines directly into the command line.
The problem I'm having is that the script executes as it is entered. I'm attempting to find a way that I can feed the script to the command line, but save execution until the entire script is complete.
Anyone have any experience around doing this? I'll admit, it isn't the ideal way to perform this, but it's what I'm faced with at the moment. Any other suggestions are welcome.
Thanks!
If you really can't write a script file to the system, you could wrap your commands in parenthesis:
same deal, multiline:
You can also wrap your script in curly braces if you don't want it to execute in a subshell:
Another way is to pipe an echo into
sh
orbash
:or use
eval
:Edit:
This also works:
cat test.sh | ssh [email protected] '/bin/bash -'
But, if you can ssh, you can just SCP the completed script up anyways? Edit, and if you can't SCP, you can:
cat test.sh | ssh [email protected] 'cat > test.sh'
No familiar with "HP's QuickTest Professional", but what stops you from writing it into a file and executing it?
I'd look at
batch
- it does almost exactly what you want.This really depends on what you mean by "not execute until you have given it all the lines". Bash is an interpreted language (not compiled), so no matter which way you slice it, shell will read and execute lines one at a time, each command will generate its own return code independently, regardless of whether you put these commands in subshells or other things.
So what I suspect you are really asking is:
(a) is there a way for you to gather all the output in one screen area without interruption
(b) is there a way for you to have to only press the "Enter" key once to have all the commands run in sequence
If you join each command line separated by a semicolon ';' then this has the same effect as running them on different lines. So string them all together on one line and press "Enter" once at the end. You may do this manually by typing, or you may process your shell script through a tool (like sed or tr) to replace End-of-Line characters with semicolons, and then feed the result into ssh. On your local host, run the following:
cat script.sh | tr "\n" ';' | ssh [remote host]
Note that this does not create an interactive shell on the remote host, it only runs the commands from the script and then returns control to your local host.