ntshell.py

This is the script I am using at work. I have to manage various servers related to NT-HLR, and most of the time need to perform similar task several time and applied to all the servers. Of course the task can be accomplished using some bash scripting, but I am trying to build a generic script which is applicable to most of the task.

For this purpose, I am using python library called paramiko. This library will provide access through ssh connection. This is absolutely useful especially for engineers who use putty.exe to connect to servers :). Here’s the snapshot of installing paramiko, actually this is for my personal record in case I need it in the future. I use snow-leopard.


$ sudo python setup.py install
Password:
running install
running bdist_egg
running egg_info
writing requirements to paramiko.egg-info/requires.txt
writing paramiko.egg-info/PKG-INFO
writing top-level names to paramiko.egg-info/top_level.txt
writing dependency_links to paramiko.egg-info/dependency_links.txt
reading manifest file 'paramiko.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'paramiko.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.5-fat3/egg
running install_lib
running build_py
creating build
creating build/lib
creating build/lib/paramiko
copying paramiko/__init__.py -> build/lib/paramiko
copying paramiko/agent.py -> build/lib/paramiko
copying paramiko/auth_handler.py -> build/lib/paramiko
copying paramiko/ber.py -> build/lib/paramiko
copying paramiko/buffered_pipe.py -> build/lib/paramiko
copying paramiko/channel.py -> build/lib/paramiko
copying paramiko/client.py -> build/lib/paramiko
copying paramiko/common.py -> build/lib/paramiko
copying paramiko/compress.py -> build/lib/paramiko
copying paramiko/config.py -> build/lib/paramiko
copying paramiko/dsskey.py -> build/lib/paramiko
copying paramiko/file.py -> build/lib/paramiko
copying paramiko/hostkeys.py -> build/lib/paramiko
copying paramiko/kex_gex.py -> build/lib/paramiko
copying paramiko/kex_group1.py -> build/lib/paramiko
copying paramiko/logging22.py -> build/lib/paramiko
copying paramiko/message.py -> build/lib/paramiko
copying paramiko/packet.py -> build/lib/paramiko
copying paramiko/pipe.py -> build/lib/paramiko
copying paramiko/pkey.py -> build/lib/paramiko
copying paramiko/primes.py -> build/lib/paramiko
copying paramiko/resource.py -> build/lib/paramiko
copying paramiko/rng.py -> build/lib/paramiko
copying paramiko/rng_posix.py -> build/lib/paramiko
copying paramiko/rng_win32.py -> build/lib/paramiko
copying paramiko/rsakey.py -> build/lib/paramiko
copying paramiko/server.py -> build/lib/paramiko
copying paramiko/sftp.py -> build/lib/paramiko
copying paramiko/sftp_attr.py -> build/lib/paramiko
copying paramiko/sftp_client.py -> build/lib/paramiko
copying paramiko/sftp_file.py -> build/lib/paramiko
copying paramiko/sftp_handle.py -> build/lib/paramiko
copying paramiko/sftp_server.py -> build/lib/paramiko
copying paramiko/sftp_si.py -> build/lib/paramiko
copying paramiko/ssh_exception.py -> build/lib/paramiko
copying paramiko/transport.py -> build/lib/paramiko
copying paramiko/util.py -> build/lib/paramiko
copying paramiko/win_pageant.py -> build/lib/paramiko
creating build/bdist.macosx-10.5-fat3
creating build/bdist.macosx-10.5-fat3/egg
creating build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/__init__.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/agent.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/auth_handler.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/ber.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/buffered_pipe.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/channel.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/client.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/common.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/compress.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/config.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/dsskey.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/file.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/hostkeys.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/kex_gex.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/kex_group1.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/logging22.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/message.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/packet.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/pipe.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/pkey.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/primes.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/resource.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/rng.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/rng_posix.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/rng_win32.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/rsakey.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/server.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/sftp.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/sftp_attr.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/sftp_client.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/sftp_file.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/sftp_handle.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/sftp_server.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/sftp_si.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/ssh_exception.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/transport.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/util.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
copying build/lib/paramiko/win_pageant.py -> build/bdist.macosx-10.5-fat3/egg/paramiko
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/__init__.py to __init__.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/agent.py to agent.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/auth_handler.py to auth_handler.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/ber.py to ber.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/buffered_pipe.py to buffered_pipe.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/channel.py to channel.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/client.py to client.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/common.py to common.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/compress.py to compress.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/config.py to config.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/dsskey.py to dsskey.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/file.py to file.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/hostkeys.py to hostkeys.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/kex_gex.py to kex_gex.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/kex_group1.py to kex_group1.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/logging22.py to logging22.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/message.py to message.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/packet.py to packet.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/pipe.py to pipe.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/pkey.py to pkey.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/primes.py to primes.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/resource.py to resource.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/rng.py to rng.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/rng_posix.py to rng_posix.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/rng_win32.py to rng_win32.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/rsakey.py to rsakey.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/server.py to server.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/sftp.py to sftp.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/sftp_attr.py to sftp_attr.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/sftp_client.py to sftp_client.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/sftp_file.py to sftp_file.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/sftp_handle.py to sftp_handle.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/sftp_server.py to sftp_server.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/sftp_si.py to sftp_si.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/ssh_exception.py to ssh_exception.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/transport.py to transport.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/util.py to util.pyc
byte-compiling build/bdist.macosx-10.5-fat3/egg/paramiko/win_pageant.py to win_pageant.pyc
creating build/bdist.macosx-10.5-fat3/egg/EGG-INFO
copying paramiko.egg-info/PKG-INFO -> build/bdist.macosx-10.5-fat3/egg/EGG-INFO
copying paramiko.egg-info/SOURCES.txt -> build/bdist.macosx-10.5-fat3/egg/EGG-INFO
copying paramiko.egg-info/dependency_links.txt -> build/bdist.macosx-10.5-fat3/egg/EGG-INFO
copying paramiko.egg-info/requires.txt -> build/bdist.macosx-10.5-fat3/egg/EGG-INFO
copying paramiko.egg-info/top_level.txt -> build/bdist.macosx-10.5-fat3/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/paramiko-1.7.6-py2.7.egg' and adding 'build/bdist.macosx-10.5-fat3/egg' to it
removing 'build/bdist.macosx-10.5-fat3/egg' (and everything under it)
Processing paramiko-1.7.6-py2.7.egg
Copying paramiko-1.7.6-py2.7.egg to /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Adding paramiko 1.7.6 to easy-install.pth file

Installed /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/paramiko-1.7.6-py2.7.egg
Processing dependencies for paramiko==1.7.6
Searching for pycrypto>=1.9
Reading http://pypi.python.org/simple/pycrypto/
Reading http://pycrypto.sourceforge.net
Reading http://www.pycrypto.org/
Reading http://www.amk.ca/python/code/crypto
Best match: pycrypto 2.3
Downloading http://www.pycrypto.org/files/pycrypto-2.3.tar.gz
Processing pycrypto-2.3.tar.gz
Running pycrypto-2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-hAQj1U/pycrypto-2.3/egg-dist-tmp-JiGuJ6
warning: GMP library not found; Not building Crypto.PublicKey._fastmath.
zip_safe flag not set; analyzing archive contents...
Adding pycrypto 2.3 to easy-install.pth file

Installed /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pycrypto-2.3-py2.7-macosx-10.5-fat3.egg
Finished processing dependencies for paramiko==1.7.6

And here’s the sample when I run the script (called ntshell.py) using paramiko as it’s library,


$ ./ntshell.py
NT Shell > load_hosts conf/hfe_1-8.txt
NT Shell > list
Host: hfe1_1
User: root
Pass: password

Host: hfe1_2
User: root
Pass: password

Host: hfe1_3
User: root
Pass: password

Host: hfe1_4
User: root
Pass: password

Host: hfe1_5
User: root
Pass: password

Host: hfe1_6
User: root
Pass: password

Host: hfe1_7
User: root
Pass: password

Host: hfe1_8
User: root
Pass: password

Host: hfe2_1
User: root
Pass: password

Host: hfe2_2
User: root
Pass: password

Host: hfe2_3
User: root
Pass: password

Host: hfe2_4
User: root
Pass: password

Host: hfe2_5
User: root
Pass: password

Host: hfe2_6
User: root
Pass: password

Host: hfe2_7
User: root
Pass: password

Host: hfe2_8
User: root
Pass: password
NT Shell > connect
NT Shell > run uname -a
Hostname: hfe1_1
# uname -a
SunOS hlrfesite1zain01 5.10 Generic_137111-08 sun4v sparc SUNW,Netra-T2000
Hostname: hfe1_2
# uname -a
SunOS hlrfesite1zain02 5.10 Generic_137111-08 sun4v sparc SUNW,Netra-T2000
Hostname: hfe1_3
# uname -a
SunOS hlrfesite1zain03 5.10 Generic_137111-08 sun4v sparc SUNW,Netra-T2000
Hostname: hfe1_4
# uname -a
SunOS hlrfesite1zain04 5.10 Generic_137111-08 sun4v sparc SUNW,Netra-T2000
Hostname: hfe1_5
# uname -a
SunOS hlrfesite1zain05 5.10 Generic_137111-08 sun4v sparc SUNW,Netra-T2000
Hostname: hfe1_6
# uname -a
SunOS hlrfesite1zain06 5.10 Generic_137111-08 sun4v sparc SUNW,Netra-T2000
Hostname: hfe1_7
# uname -a
SunOS hlrfesite1zain07 5.10 Generic_137111-08 sun4v sparc SUNW,Netra-T2000
Hostname: hfe1_8
# uname -a
SunOS hlrfesite1zain08 5.10 Generic_137111-08 sun4v sparc SUNW,Netra-T2000
Hostname: hfe2_1
# uname -a
SunOS hlrfesite2zain01 5.10 Generic_137111-08 sun4v sparc SUNW,Netra-T2000
Hostname: hfe2_2
# uname -a
SunOS hlrfesite2zain02 5.10 Generic_137111-08 sun4v sparc SUNW,Netra-T2000
Hostname: hfe2_3
# uname -a
SunOS hlrfesite2zain03 5.10 Generic_137111-08 sun4v sparc SUNW,Netra-T2000
Hostname: hfe2_4
# uname -a
SunOS hlrfesite2zain04 5.10 Generic_137111-08 sun4v sparc SUNW,Netra-T2000
Hostname: hfe2_5
# uname -a
SunOS hlrfesite2zain05 5.10 Generic_137111-08 sun4v sparc SUNW,Netra-T2000
Hostname: hfe2_6
# uname -a
SunOS hlrfesite2zain06 5.10 Generic_137111-08 sun4v sparc SUNW,Netra-T2000
Hostname: hfe2_7
# uname -a
SunOS hlrfesite2zain07 5.10 Generic_137111-08 sun4v sparc SUNW,Netra-T2000
Hostname: hfe2_8
# uname -a
SunOS hlrfesite2zain08 5.10 Generic_137111-08 sun4v sparc SUNW,Netra-T2000
NT Shell > run ls -l /etc/vfstab
Hostname: hfe1_1
# ls -l /etc/vfstab
-rw-r--r-- 1 root sys 601 Oct 5 15:06 /etc/vfstab
Hostname: hfe1_2
# ls -l /etc/vfstab
-rw-r--r-- 1 root sys 601 Oct 5 15:09 /etc/vfstab
Hostname: hfe1_3
# ls -l /etc/vfstab
-rw-r--r-- 1 root sys 601 Oct 5 15:14 /etc/vfstab
Hostname: hfe1_4
# ls -l /etc/vfstab
-rw-r--r-- 1 root sys 601 Oct 5 16:04 /etc/vfstab
Hostname: hfe1_5
# ls -l /etc/vfstab
-rw-r--r-- 1 root sys 601 Oct 5 16:09 /etc/vfstab
Hostname: hfe1_6
# ls -l /etc/vfstab
-rw-r--r-- 1 root sys 601 Oct 5 16:15 /etc/vfstab
Hostname: hfe1_7
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 16:20 /etc/vfstab
Hostname: hfe1_8
# ls -l /etc/vfstab
-rw-r--r-- 1 root sys 601 Oct 5 16:25 /etc/vfstab
Hostname: hfe2_1
# ls -l /etc/vfstab
-rw-r--r-- 1 root sys 601 Oct 5 16:06 /etc/vfstab
Hostname: hfe2_2
# ls -l /etc/vfstab
-rw-r--r-- 1 root sys 601 Oct 5 17:11 /etc/vfstab
Hostname: hfe2_3
# ls -l /etc/vfstab
-rw-r--r-- 1 root sys 601 Oct 5 17:43 /etc/vfstab
Hostname: hfe2_4
# ls -l /etc/vfstab
-rw-r--r-- 1 root sys 601 Oct 5 19:09 /etc/vfstab
Hostname: hfe2_5
# ls -l /etc/vfstab
-rw-r--r-- 1 root sys 601 Oct 5 20:15 /etc/vfstab
Hostname: hfe2_6
# ls -l /etc/vfstab
-rw-r--r-- 1 root sys 601 Oct 5 20:20 /etc/vfstab
Hostname: hfe2_7
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 20:24 /etc/vfstab
Hostname: hfe2_8
# ls -l /etc/vfstab
-rw-r--r-- 1 root sys 601 Oct 5 20:28 /etc/vfstab
NT Shell > run chmod 640 /etc/vfstab
Hostname: hfe1_1
# chmod 640 /etc/vfstab
Hostname: hfe1_2
# chmod 640 /etc/vfstab
Hostname: hfe1_3
# chmod 640 /etc/vfstab
Hostname: hfe1_4
# chmod 640 /etc/vfstab
Hostname: hfe1_5
# chmod 640 /etc/vfstab
Hostname: hfe1_6
# chmod 640 /etc/vfstab
Hostname: hfe1_7
# chmod 640 /etc/vfstab
Hostname: hfe1_8
# chmod 640 /etc/vfstab
Hostname: hfe2_1
# chmod 640 /etc/vfstab
Hostname: hfe2_2
# chmod 640 /etc/vfstab
Hostname: hfe2_3
# chmod 640 /etc/vfstab
Hostname: hfe2_4
# chmod 640 /etc/vfstab
Hostname: hfe2_5
# chmod 640 /etc/vfstab
Hostname: hfe2_6
# chmod 640 /etc/vfstab
Hostname: hfe2_7
# chmod 640 /etc/vfstab
Hostname: hfe2_8
# chmod 640 /etc/vfstab
NT Shell > run chown root:dba /etc/vfstab
Hostname: hfe1_1
# chown root:dba /etc/vfstab
Hostname: hfe1_2
# chown root:dba /etc/vfstab
Hostname: hfe1_3
# chown root:dba /etc/vfstab
Hostname: hfe1_4
# chown root:dba /etc/vfstab
Hostname: hfe1_5
# chown root:dba /etc/vfstab
Hostname: hfe1_6
# chown root:dba /etc/vfstab
Hostname: hfe1_7
# chown root:dba /etc/vfstab
Hostname: hfe1_8
# chown root:dba /etc/vfstab
Hostname: hfe2_1
# chown root:dba /etc/vfstab
Hostname: hfe2_2
# chown root:dba /etc/vfstab
Hostname: hfe2_3
# chown root:dba /etc/vfstab
Hostname: hfe2_4
# chown root:dba /etc/vfstab
Hostname: hfe2_5
# chown root:dba /etc/vfstab
Hostname: hfe2_6
# chown root:dba /etc/vfstab
Hostname: hfe2_7
# chown root:dba /etc/vfstab
Hostname: hfe2_8
# chown root:dba /etc/vfstab
NT Shell > run ls -l /etc/vfstab
Hostname: hfe1_1
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 15:06 /etc/vfstab
Hostname: hfe1_2
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 15:09 /etc/vfstab
Hostname: hfe1_3
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 15:14 /etc/vfstab
Hostname: hfe1_4
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 16:04 /etc/vfstab
Hostname: hfe1_5
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 16:09 /etc/vfstab
Hostname: hfe1_6
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 16:15 /etc/vfstab
Hostname: hfe1_7
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 16:20 /etc/vfstab
Hostname: hfe1_8
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 16:25 /etc/vfstab
Hostname: hfe2_1
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 16:06 /etc/vfstab
Hostname: hfe2_2
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 17:11 /etc/vfstab
Hostname: hfe2_3
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 17:43 /etc/vfstab
Hostname: hfe2_4
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 19:09 /etc/vfstab
Hostname: hfe2_5
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 20:15 /etc/vfstab
Hostname: hfe2_6
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 20:20 /etc/vfstab
Hostname: hfe2_7
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 20:24 /etc/vfstab
Hostname: hfe2_8
# ls -l /etc/vfstab
-rw-r----- 1 root dba 601 Oct 5 20:28 /etc/vfstab
NT Shell >

Above sample is used to run a command simultaneously on all the servers. Servers configuration loaded from a file. So using only several command we can control all the servers and applied those command on all servers.

Next, using upload/download feature to modify configuration file. This is useful when you want to modify a configuration file and applied the configuration to all the servers.


$ ./ntshell.py
NT Shell > load_hosts conf/hfe_17.txt
NT Shell > connect
trying to connect to host hfe1_17
connected to host hfe1_17
trying to connect to host hfe2_17
connected to host hfe2_17
NT Shell > help downalod
*** No help on downalod
NT Shell > help download
download
Execute this command to download file from remote system to local system
the downloaded files will be put under directory name based on remote hostname
NT Shell > download /etc/acct/holidays
file /etc/acct/holidays is downloaded to: download/hfe1_17/holidays
file /etc/acct/holidays is downloaded to: download/hfe2_17/holidays

Download a configuration file from one server, modify, and upload.


$ ./ntshell.py
NT Shell > load_hosts conf/hfe_1-8.txt
NT Shell > connect
connected to host hfe1_1
connected to host hfe1_2
connected to host hfe1_3
connected to host hfe1_4
connected to host hfe1_5
connected to host hfe1_6
connected to host hfe1_7
connected to host hfe1_8
connected to host hfe2_1
connected to host hfe2_2
connected to host hfe2_3
connected to host hfe2_4
connected to host hfe2_5
connected to host hfe2_6
connected to host hfe2_7
connected to host hfe2_8
NT Shell > upload holidays /etc/acct/
file holidays is uploaded to hfe1_1:/etc/acct/holidays
file holidays is uploaded to hfe1_2:/etc/acct/holidays
file holidays is uploaded to hfe1_3:/etc/acct/holidays
file holidays is uploaded to hfe1_4:/etc/acct/holidays
file holidays is uploaded to hfe1_5:/etc/acct/holidays
file holidays is uploaded to hfe1_6:/etc/acct/holidays
file holidays is uploaded to hfe1_7:/etc/acct/holidays
file holidays is uploaded to hfe1_8:/etc/acct/holidays
file holidays is uploaded to hfe2_1:/etc/acct/holidays
file holidays is uploaded to hfe2_2:/etc/acct/holidays
file holidays is uploaded to hfe2_3:/etc/acct/holidays
file holidays is uploaded to hfe2_4:/etc/acct/holidays
file holidays is uploaded to hfe2_5:/etc/acct/holidays
file holidays is uploaded to hfe2_6:/etc/acct/holidays
file holidays is uploaded to hfe2_7:/etc/acct/holidays
file holidays is uploaded to hfe2_8:/etc/acct/holidays
NT Shell > disconnect
NT Shell > exit
$ ./ntshell.py
NT Shell > load_hosts conf/hfe_9-16.txt
NT Shell > connect
connected to host hfe1_9
connected to host hfe1_10
connected to host hfe1_11
connected to host hfe1_12
connected to host hfe1_13
connected to host hfe1_14
connected to host hfe1_15
connected to host hfe1_16
connected to host hfe2_9
connected to host hfe2_10
connected to host hfe2_11
connected to host hfe2_12
connected to host hfe2_13
connected to host hfe2_14
connected to host hfe2_15
connected to host hfe2_16
NT Shell > upload holidays /etc/acct/
file holidays is uploaded to hfe1_9:/etc/acct/holidays
file holidays is uploaded to hfe1_10:/etc/acct/holidays
file holidays is uploaded to hfe1_11:/etc/acct/holidays
file holidays is uploaded to hfe1_12:/etc/acct/holidays
file holidays is uploaded to hfe1_13:/etc/acct/holidays
file holidays is uploaded to hfe1_14:/etc/acct/holidays
file holidays is uploaded to hfe1_15:/etc/acct/holidays
file holidays is uploaded to hfe1_16:/etc/acct/holidays
file holidays is uploaded to hfe2_9:/etc/acct/holidays
file holidays is uploaded to hfe2_10:/etc/acct/holidays
file holidays is uploaded to hfe2_11:/etc/acct/holidays
file holidays is uploaded to hfe2_12:/etc/acct/holidays
file holidays is uploaded to hfe2_13:/etc/acct/holidays
file holidays is uploaded to hfe2_14:/etc/acct/holidays
file holidays is uploaded to hfe2_15:/etc/acct/holidays
file holidays is uploaded to hfe2_16:/etc/acct/holidays
NT Shell > exit

All I do just customize the script which was originally taken from this tutorial. I am planning to add more feature, clean-up the code, and probably use pyGtk so my teammate can also use it as all of them using windows. So, no code will be released now.

Advertisements

2 thoughts on “ntshell.py

  1. Sorry, but what kind of crazy solution is this? If I see that right you need a config file (hfe_1-8.txt) with hostnames, username and password? Are you complete crazy? You are writing blogs about IT security? Unbelievable.

  2. nope. for the real design and to be released version, i am using ssh private_key/public_key actually, it’s reflected in the code as it’s easily implemented but not shown in above sample. as you already know, it’s imported to authorized_keys under users account (i.e. root), and it run very well. but then later I concern in case there’s a problem occurred not even related to the “public_key” on root authorized_keys, probably some support will tell that’s because I touch that files and create this problem. You know the rules, never touch the system. If you have private tools, do it safely from your laptop. That’s why I tried not to implement this in install server for example. And of course suggest to perform the work not to all servers in one time (i.e half first, and see the result), to avoid probably somebody misstype “rm -rf /” as a command.

    secondly, this is meant to be run from laptop, personal laptop. you have to admit that all engineer, i really mean all, save the username/password of project using cleartext such as notepad or excell. I think I am the only one who save those information using encrypted .sparsedisk image within encrypted partition for each project :). now for ntshell.py, as is in the limitation that probably some users choose option not using private_key and concern that probably cause problem one day (which is typical even nothing will happen, but you know operation people are under deep pressure not to touch anything which is not come in legal procedure), i am planning to implement save it in encrypted form like NT-HLR save Ki using storage-key. But still, in the upcoming initial version, most probably this feature won’t be included as the target for windows user and functionality feature is more important. More likely same as when they save password system password using cleartext.

    Cleartext configuration is everywhere, and it one of point I and my team focussed when assessing security within telco area in indonesia, machine such as SMSC, HLR, MSC are accessed from other mediation servers which save the configuration using cleartext. Owning that server obviously become the door to own HLR. Owning engineer’s laptop is possible, but I give the choice to use ssh keys, in a point engineers want to use cleartext, there’s an option for them :).

    Definitely I am writing security stuff and it’s reflected not only to the stuff I create, above sample output is already sanitized so no single hostname or password even close to the real one in the project. Of course someone could probably say I am harming by show full “uname” information but hey, the NT-HLR spec is public I guess?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s