0

Am trying Cloudera Manager APIs with the help of Python in AWS. I was trying to execute some commands in the Zookeeper Command Line Interface after executing the script 'zkCli.sh'. I have tried using the below command using subprocess and am able to login to the zookeeper cli.

subprocess.call('ssh -o StrictHostKeyChecking=no -t -t -i /home/ec2-user/key.pem ec2-user@xx.xx.xx.xx "sudo /opt/cloudera/parcels/CDH/lib/zookeeper/bin/zkCli.sh"', shell=True)

Can anybody help me to execute other commands in the zookeeper cli (say 'ls /') using the same subprocess.

Is there any other methods to achieve the above case in Python ?

Hajas
  • 115
  • 1
  • 3
  • 10
  • does it have to be python? – Michelle Tan Mar 15 '17 at 10:50
  • @MichelleTan I was trying with the _cloudera manager api_ in python. If there is no other options in python, am ready to try any other options. The whole intention is to automate command execution in zookeeper cli – Hajas Mar 16 '17 at 09:47

1 Answers1

1

Not sure about the cloudera API. You can maybe use Python to execute a script. Have you tried Heredoc? https://en.wikipedia.org/wiki/Here_document You could run it on the terminal or put in in a shell script to execute it automatically.It would be something like this:

bin/zkCli.sh -server localhost:2181 << END create /zookeeper/Testing "Testdata" quit END

or even output into a log file

bin/zkCli.sh -server localhost:2181 >> zkAutomation.log << END create /zookeeper/Testing "Testdata" quit END

Michelle Tan
  • 385
  • 4
  • 10
  • Thanks @Michelle Tan for the response. I have tried out this and am able to execute my commands in the zookeeper cli. I have created a shell script and I executed that script from the Python and there by am able to automate my job with the same Python script.. :) – Hajas Mar 17 '17 at 12:57