1

I want to execute a jar file of DOMO CLI from a shell script. The jar file itself has some functions which I want to call after I call the main jar file. The problem which I am facing is that after it executes the jar file, I am not able to pass the additional commands to execute inside that jar through a shell script. It just stops after calling jar and doesn't take further commands. Can anyone please help? Below is the code I am calling from a shell script.

java -jar XX.jar

The commands are as below which follow the above jar. So once we enter into the above jar we have to execute the below commands one after the other. I am not sure how to achieve this through a shell script.

connect -s X.domo.com -t Ysssss

upload-dataset -a -i dhdhdhdh -f /prehdfs/dev/comres/herm/data/yyyy.csv
Pritesh
  • 1,066
  • 3
  • 15
  • 35
Yogesh
  • 47
  • 1
  • 10
  • 1
    `java -jar XX.jar &` will start the `java` process and run it in the background (so your other commands will then execute). – Elliott Frisch Jul 24 '19 at 04:56
  • @ElliottFrisch it does start the java process but it doesn't run the commands after that. It is showing the blank screen thereafter. I have executed like below: java -jar XX.jar & connect -s X.domo.com -t Ysssss – Yogesh Jul 24 '19 at 04:59
  • Are those lines are meant to be supplied on standard in to the java process? If so, take a look at [expect](https://www.geeksforgeeks.org/expect-command-in-linux-with-examples/). – Elliott Frisch Jul 24 '19 at 05:14
  • @ElliottFrisch : I don't see any `&` in the post! – user1934428 Jul 24 '19 at 06:51
  • @yogesh: In what way does the Java program expect the additional input? By command line, via stdin, via some configuration file .... ? – user1934428 Jul 24 '19 at 06:55
  • @user1934428 yes through command line, I have to run these additional commands like connect, upload etc after executing jar. But these have to be run in shell script. Please suggest. – Yogesh Jul 24 '19 at 08:48
  • So why don't you just add the additional parameters on the command line? `java -jar XX.jar PARAMETER1 PARAMETER2 ....`. – user1934428 Jul 24 '19 at 11:29
  • @user1934428 that doesn't work either. I have tried this already. It doesnt take those parameters. – Yogesh Jul 25 '19 at 04:26
  • @Yogesh : From this, I would conclude that the Java program is not designed to access `argv`. BTW, this problem has already been discussed [here](https://stackoverflow.com/questions/456636/how-do-i-pass-parameters-to-a-jar-file-at-the-time-of-execution) – user1934428 Jul 25 '19 at 06:36

2 Answers2

1

Did you try using pipes and inputs. When you execute above it runs it under a child shell.

You may try below format if not tried already

$ (echo "connect -s X.domo.com -t Ysssss" && cat) | java -jar XX.jar
Amit
  • 13
  • 5
  • The code you provided works but if I try to run the another code together, it fails to execute. I am executing code like this: (echo "connect -s X.domo.com -t Ysssss" && upload-dataset -a -i dhdhdhdh -f /prehdfs/dev/comres/herm/data/yyyy.csv && cat) | java -jar XX.jar .... It gives error "No such file or directory" on /prehdfs/dev/comres/herm/data/yyyy.csv. Any suggestions? – Yogesh Jul 24 '19 at 05:04
  • it is working only to run 1 command, but if more than 1 needs to be run, it is giving error. – Yogesh Jul 24 '19 at 06:05
  • What is the output of $ls -alt /prehdfs/dev/comres/herm/data/yyyy.csv – Amit Jul 30 '19 at 05:37
0

If you can reference a file in your use case, you could put your commands in a file.

File: list_my_datasets.domo

connect -t ... -s ...
list-dataset
quit

then run the command:

java -jar domoUtil.jar -script list_my_datasets.domo > datasets

I wanted the data from it so I piped to a file (where I had to grep what I wanted), but you would omit that I believe, unless it has some output you'd want to check. I haven't tested with the upload command, but I would hope any commands substituted or added to the example work similarly.

Domo docs on scripting

ARobertson
  • 2,857
  • 18
  • 24