2

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!

6 Answers 6

3

If you really can't write a script file to the system, you could wrap your commands in parenthesis:

 ( ls; echo this; echo that; )

same deal, multiline:

(
ls
echo this
echo that
)
1
  • Thanks for all of the answers everyone. I'm still open to more suggestions on how to complete this task, but this answer works perfectly for the current problem.
    – MHGL
    Mar 18, 2010 at 16:41
3

You can also wrap your script in curly braces if you don't want it to execute in a subshell:

{
echo one
echo two
}

Another way is to pipe an echo into sh or bash:

echo '
echo one
echo two
' | bash

or use eval:

eval '
echo one
echo two
'

Edit:

This also works:

bash <<EOF
echo one
echo two
EOF
1

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'

1
0

No familiar with "HP's QuickTest Professional", but what stops you from writing it into a file and executing it?

0

I'd look at batch - it does almost exactly what you want.

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .