Skip to content

Instantly share code, notes, and snippets.

@PSJoshi
PSJoshi / linux tips
Last active August 29, 2015 14:14
Linux tips
How to Zip the files from given start date to end date
### find all files that were modified less than 29 days ago and more than 21 days ago.
# find . -type f -mtime -29 -mtime +21 | zip -@ my.zip
# tar cvf - `find . -type f -mtime -29 -mtime +21` | gzip -c 1>061110_061201.tgz
# find largest files
# du -m /some/path | sort -nr | head -n 20
# find / -type f -size +20M -exec ls -lh {} \;
@PSJoshi
PSJoshi / Latest files
Last active August 29, 2015 14:14
Find latest modified files in python
def Latest_files(options, roots):
"""" A generator to enumerate the contents of directories recursively. """
for root in roots:
for dirpath, dirnames, filenames in os.walk(root):
name = os.path.split(dirpath)[1]
if any(fnmatch.fnmatch(name, w) for w in options.exc_dirs):
del dirnames[:] # Don't recurse here
continue
for fn in filenames:
if any(fnmatch.fnmatch(fn, w) for w in options.exc_files):
@PSJoshi
PSJoshi / setuptools and pip installation
Last active August 29, 2015 14:14
Python setuptools and pip installation
# Install latest setuptools and pip
# get the setup script for Setuptools:
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
# Then install it for Python 2.7 and/or Python 3.3:
python2.7 ez_setup.py
python3.3 ez_setup.py
# Install pip using the newly installed setuptools:
@PSJoshi
PSJoshi / security-onion tips
Created January 28, 2015 11:57
security onion tips
# restart netsniff-ng
#sudo nsm --sensor --restart --only-pcap
# status of all nsm process
# sudo service nsm status
@PSJoshi
PSJoshi / file creation and modification times
Created February 9, 2015 16:21
python - file creation and modification times
# file creation and modification times
import os.path, time
print "last modified: %s" % time.ctime(os.path.getmtime(file_name))
print "created: %s" % time.ctime(os.path.getctime(file_name))
@PSJoshi
PSJoshi / add path
Last active August 29, 2015 14:15
Adding path in linux
#Edit .bashrc in your home directory and add the following line:
export PATH=/usr/local/bin:/opt/bro/bin:$PATH
#To source your .bashrc, simply type
$ source .bashrc
in the home directory.
@PSJoshi
PSJoshi / error_handling
Created February 23, 2015 08:26
python error handling
try:
raise Exception('blabla')
except Exception:
logging.info('blabla', exc_info=True)
import sys
import traceback
try:
@PSJoshi
PSJoshi / Kibana 3 and Elasticsearch 1.4 - CORS issue
Created March 1, 2015 04:00
Kibana 3 and Elasticsearch 1.4 - CORS problem
If you setup Kibana 3 with ElasticSearch 1.4, it throws "Connection Failed" error . The way to fix is:
http.cors.allow-origin: "/.*/"
#http.cors.allow-origin: "*"
http.cors.enabled: true
@PSJoshi
PSJoshi / python-string
Last active August 29, 2015 14:16
python string cookbook
z= "{} is here".format("joshi")
print(" To escape {} bracket, add double brackets like this - {{0}} ".format("empty"))
Very good examples available here - https://mkaz.com/2012/10/10/python-string-format/
@PSJoshi
PSJoshi / bro-cron scripts
Created March 7, 2015 16:07
Bro cron scripts
#start bro at boot - /etc/rc.local
/usr/local/bro/bin/broctl start
exit 0
#Housecleaning items every five minutes via broctl cron - /etc/crontab
0-59/5 * * * * root /usr/local/bro/bin/broctl cron