Automate multiple users creation and set passwords, SSH keys and more using Ansible.
#Ansible is so beautiful yet cool to complementing #SALT to be deployed across all hosts
Run Salt Minion in a Python3 Virtual Environment
Having trouble with Copy/Paste or Drag n Drop between Windows host and VMWare Workstation VMs?
Checkout this blog to fix it!
Vagrant is one of the best example of Infrastructure as a Code (IAC) tools (VM based). It works based on the declarative configuration file which consists of requirements like OS, Apps, Users and Files etc… By using Vagrant, we can reduce mundane tasks of downloading … Continue reading Vagrant :: SSH Inter-Connectivity of Multi Virtual Machines
An easy step by step guide to install and configure #Go #Golang on #Raspberry #Pi also applicable to #Linux distributions such as #Debian #Ubuntu
What is Docker? Docker is a computer program that performs operating-system-level virtualization, also known as “containerization”. It was first released in 2013 and is developed by Docker, Inc. source: Wikipedia How Docker works? Docker containers wrap up software and its dependencies into a standardized unit for … Continue reading Docker’ize’ Python
Is your script/code looks dull and not in order? If yes, then its time to use pycodestyle!! Pycodestyle (formerly known as PEP8) is a syntax and style checker tool for Python language. In this blog, I’ve documented step by step procedure to install this with … Continue reading Pycodestyle @ Sublime Text
Wish you all Happy, Prosperous & Pythonic New Year 2019!!
I thank everyone for stopping by my blog for 15K times in 2018 which is the highest so far!
“Looking back at my life’s voyage, I can only say that it has been a good trip.” ~ Ginger Rogers
Similar to the above quote, I’d started my scripting voyage by writing shell, batch and Perl scripts in good old days. I miss some of the awesome, builtin & yet simple to use features available in shell. I felt using those features or builtins would make my life easier while writing scripts in Python…
Besides that, one main reason to look back at the past was while imparting the Python Workshop at my office. One of the participants raised concerns over Python’s builtin modules like OS and Subprocess. They mentioned we can accomplish with very simple steps in ‘Shell’ instead of using OS or Subprocess module. I had to accept the fact that sometimes Python is not so easy as we think!
After googling for a while I finally found this… Say hola to ‘sh‘ Module!
The ‘sh’ library provides simple and intuitive alternative to OS/System/Subprocess modules.
‘sh’ module simplifies Python’s ability to interact with native OS by calling shell commands. This would greatly helps in automation of routine tasks and running sequence of commands, parsing output as per requirement.
Python is a powerful language powered by those great developers who are continuously contributing to enable new features every day in day out. I would like to thank Andrew Moffat for the ‘sh’ library. This library is one of my favourites.
To install this library using PIP, run below command
pip3 install sh
Please find sample scripts output.
>>> import sh
7:13 up 11 days, 23:29, 4 users, load averages: 1.51 1.65 1.88
>>> sh.echo(‘Hello, This is shell\’s echo running from Python’)
Hello, This is shell's echo running from Python
vinay console Dec 21 07:45
vinay ttys000 Dec 21 07:46
vinay ttys001 Dec 21 07:46
vinay ttys003 Jan 2 07:02
Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on
/dev/disk1s1 236568496 96124200 131754736 43% 1042911 9223372036853732896 0% /
devfs 376 376 0 100% 653 0 100% /dev
/dev/disk1s4 236568496 6291496 131754736 5% 3 9223372036854775804 0% /private/var/vm
map -hosts 0 0 0 100% 0 0 100% /net
map auto_home 0 0 0 100% 0 0 100% /home
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
XHC20: flags=0<> mtu 0
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
inet6 fe80::149c:1b88:578c:73f8%en0 prefixlen 64 secured scopeid 0x5
inet 192.168.1.9 netmask 0xffffff00 broadcast 192.168.1.255
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
awdl0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1484
inet6 fe80::880c:61ff:fe9e:649b%awdl0 prefixlen 64 scopeid 0x7
en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
media: autoselect <full-duplex>
en2: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
media: autoselect <full-duplex>
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
ipfilter disabled flags 0x2
member: en1 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 8 priority 0 path cost 0
member: en2 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 9 priority 0 path cost 0
media: <unknown type>
utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000
inet6 fe80::bd0:9dea:48de:5645%utun0 prefixlen 64 scopeid 0xb
Thanks for stopping by, please share your comments and ideas to improve this blog. Keep watching for more Python libraries used for automation.
Nowadays most of the Linux distros do not include Telnet. If needed we can install it using the usual methods.
Let’s embrace Netcat which is a best alternative to Telnet. Earlier I had written a Perl script which did Telnet and Ping checks across multiple hosts.
This script requires two input files ips.csv and ports.csv. As the name suggest all target host IP’s to be placed in ips.csv file and the ports to which to netcat is placed in ports.csv. Output is in HTML format and user receives an email with colour coded results.
Replace ips.csv & ports.csv file contents and change SMTP IP and email address.
Here is the Python script which replaces Telnet with Netcat.