Skip to content

Instantly share code, notes, and snippets.

@samuelsh
samuelsh / shell_utils.py
Created August 3, 2016 06:52
Set of shell utils that allows to run shell commands, shell scripts and bash functions on local and remote hosts
class ShellUtils:
def __init__(self):
pass
@staticmethod
def run_bash_function(library_path, function_name, params):
cmdline = ['bash', '-c', '. %s; %s %s' % (library_path, function_name, params)]
p = subprocess.Popen(cmdline,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
@samuelsh
samuelsh / rdir.py
Created June 28, 2016 12:59
Python directory tree generator, using recursion
#!/usr/bin/python2.6
import sys
import os
def build_dir_tree(base, depth, width):
print("Call #%d" % depth)
if depth >= 0:
curr_depth = depth
depth -= 1
@samuelsh
samuelsh / generic_multiprocess_dir_crawler.py
Last active November 17, 2022 06:53
Generic multiprocessing directory tree walker and file crawler.Directory tree walker and file scanner processes are running in parallel which make it pretty fast.It uses python multiprocessing.
#!/usr/bin/python
import multiprocessing
import os
import subprocess
import os.path
import sys
from Queue import Empty
from multiprocessing import Process, Pool
from optparse import OptionParser
import traceback
@samuelsh
samuelsh / dir_wlaker_multiprocess.py
Created March 24, 2016 12:54
parallel directory walker, based on python multiprocessing. It twice faster then dir_waker_threads but is not OO
import argparse
import multiprocessing
from multiprocessing import Pool, Queue
from multiprocessing import Manager
import os
unsearched = Manager().Queue()
dirpath_queue = Queue()
@samuelsh
samuelsh / dir_walker_threads.py
Last active July 13, 2018 13:43
parallel directory walker using python's threads (multiprocessing dummy)
import argparse
import multiprocessing
from multiprocessing.dummy import Pool, Queue
from multiprocessing import Manager
import os
class TreeCrawler(object):
def __init__(self, base_path, callback=None):
@samuelsh
samuelsh / RSA_keys_generator.py
Last active August 29, 2015 14:27
Method genetates id_rsa and id_rsa.pub on client
def RSA_keys_generator(complexity=2048):
"""
Method generates id_rsa and id_rsa.pub on client. Tested on CentOS 6.x clients
"""
import paramiko
k = paramiko.RSAKey.generate(complexity)
k.write_private_key_file(os.path.expanduser('~/.ssh/id_rsa'))
with open(os.path.expanduser('~/.ssh/id_rsa.pub'), "w") as f: