0

I'm trying to automate the installation of Sqoop 2. Suppose the sqoop-server is installed in the ip address 1.2.3.4. On the sqoop-client I want to set that server's ip. Manually, to do so, I would:

sqoop2
sqoop:000> set server --host 1.2.3.4

how could I accomplish that using shell's pipe and echo? I've tried

set server --host 1.2.3.4 | sqoop2 

but it didn't quite work.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
cybertextron
  • 10,547
  • 28
  • 104
  • 208
  • The `set` command set command line arguments `$1`, `$2`, and `$3` for the shell on the LHS of the pipeline, which then exited without providing any input to `sqoop2`. That's why it didn't work. – Jonathan Leffler Jul 27 '14 at 16:28

2 Answers2

3

Many interactive programs read from stdin. Assuming this is the case for sqoop2 you might use a pipe as you suggested. But you just forget to use the echo command:

echo set server --host 1.2.3.4 | sqoop2

The code above set the output of echo as the input of sqoop2. An other option is to use a here string

sqoop2 <<< "set server --host 1.2.3.4"

A third option is to use a here doc. Very useful if you have to send multiple commands:

sqoop2 << 'EOF'
set server --host 1.2.3.4
EOF

(in the above, you might issue as many command as you want before the EOF marker that ends the heredoc then the shell will send all the commands to the programs sqoop2 as its standard input)

Sylvain Leroux
  • 50,096
  • 7
  • 103
  • 125
0

Use expect(1) to script interactive programs.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469