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 ?
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