Friday, 22 May 2020

How to ssh in a shell script




How to make ssh seamless for linux shell scripts





Sometimes we have trouble running ssh via shell script which loops through a huge list of hosts with key authorization and we face many issues like below :


  • a host is highly loaded that holds the session
  • host is not reachable
  • prompting for password 
  • you want to make ssh fail rather than prompt for password if the public key authorization fails 
  • prompting for typing 'yes/no' 


Solution which takes care of the everything above :

ssh -oBatchMode=yes -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ConnectTimeout=5 -o PasswordAuthentication=no username@<hostname> "Do Stuff" 






Sunday, 10 May 2020

Kafka Python Create a Kafka Topic




Creating a kafka Topic Using Kafka Python Modules


1. Import python module

import kafka

2. Make Connection

admin_client = KafkaAdminClient(bootstrap_servers=[broker_host])

3. Get list of toipcs

topic_list = []
topic_list.append(NewTopic(name=bucket_name,
num_partitions=num_part, replication_factor=repl_factor))

4. Create Topics
admin_client.create_topics(new_topics=topic_list,validate_only=False)

5. Closing connection
admin_client.close()