Monday, November 4, 2013

Python in Action: ssh paramiko client - first release to github

I have been working on the same codes for almost a week from now. I feel that I am more comfortable with the output and I decided to push it over to github and hope that it could help others system engineer who needed to do the automation with a large group of servers/VMs. You can clone the codes from here.


Here is the output that you will be getting.


hiuy@nasilemak ~/ssh-paramiko-client $ ./pyssh.py
Password:
-- Welcome to ssh paramiko --
ssh > help
Usage - pyssh.py
 addhost      - add host with the comma delimitter
 addhostfile  - add host with a absolute path of a file
 rmhost       - remove host with the comma delimitter
 lshost       - list hosts
 ping         - do a ping test to the added host list
 connect      - establish ssh connection to the added host list
 run          - run a specific command on the connected host
 close        - close the ssh connect to the added host list
 quit         - quit the session

ssh > addhost centos64-1, centos64-2
host added: ['centos64-1', 'centos64-2']
ssh > ping
host centos64-1 PING OK
host centos64-2 PING OK
ssh > connect
Connected host: centos64-1
Connected host: centos64-2
Total connected hosts: 2 out of 2
ssh > run uptime
host: centos64-1
     05:49:07 up  4:24,  1 user,  load average: 0.00, 0.10, 0.10
host: centos64-2
     05:49:07 up  4:25,  1 user,  load average: 0.00, 0.00, 0.00
ssh > run uname -a
host: centos64-1
    Linux localhost.localdomain 2.6.32-358.23.2.el6.x86_64 #1 SMP Wed Oct 16 18:37:12 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
host: centos64-2
    Linux localhost.localdomain 2.6.32-358.23.2.el6.x86_64 #1 SMP Wed Oct 16 18:37:12 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
ssh > run rpm -qa | grep kernel
host: centos64-1
    kernel-devel-2.6.32-358.el6.x86_64
    kernel-headers-2.6.32-358.23.2.el6.x86_64
    abrt-addon-kerneloops-2.0.8-16.el6.centos.1.x86_64
    dracut-kernel-004-303.el6.noarch
    libreport-plugin-kerneloops-2.0.9-15.el6.centos.1.x86_64
    kernel-firmware-2.6.32-358.23.2.el6.noarch
    kernel-devel-2.6.32-358.23.2.el6.x86_64
    kernel-2.6.32-358.el6.x86_64
    kernel-2.6.32-358.23.2.el6.x86_64
host: centos64-2
    kernel-devel-2.6.32-358.el6.x86_64
    kernel-headers-2.6.32-358.23.2.el6.x86_64
    abrt-addon-kerneloops-2.0.8-16.el6.centos.1.x86_64
    dracut-kernel-004-303.el6.noarch
    libreport-plugin-kerneloops-2.0.9-15.el6.centos.1.x86_64
    kernel-firmware-2.6.32-358.23.2.el6.noarch
    kernel-devel-2.6.32-358.23.2.el6.x86_64
    kernel-2.6.32-358.el6.x86_64
    kernel-2.6.32-358.23.2.el6.x86_64
ssh > close
ssh > quit
hiuy@nasilemak ~/ssh-paramiko-client $


If you are keen to develop and contribute to this codes, please drop me an email, and we can work it out together. All of the new ideas are mostly welcome. Thanks.

Sunday, November 3, 2013

visudo: Are you really a joker?

What you see sometimes doesn't mean what you think!

I just came across a funny configuration bits on the /etc/sudoers file lately on centos64. The default configuration for /etc/sudoers comes with this (the last 2 lines at the config). Okay, gentlemen. Please pay attention with this. If you would be creating a directory like /etc/sudoers.d/, then basically you are asking sudoer to look at any of the small snippets with in it, or what they called it as drop-in files. Make sure you do have the snippet and stay within this directory. Otherwise, your visudo -c -f /etc/sudoers will complain and shout at you when you save it.

What is make me laugh at it was the syntax of the configuration #includedir. It is telling you that it has been turned on. Don't be fooled because it was commented out (as usual, a sys admin will think the same across, further more most of the tags was commented out). It *doesnt* mean what you think. So, watch out! It bites you!

## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d