Skip to content

Instantly share code, notes, and snippets.

@imranbhullar
imranbhullar / readme
Last active March 17, 2023 16:44
This script updates all the outdated vagrant boxes and deletes the outdated box post update (one at a time).
Vagrant Box Updater
This script updates Vagrant boxes on your machine to the latest version, one at a time. It removes all versions of each box before updating to the latest version.
Usage:
1. Open a terminal window.
2. Navigate to the directory where the script is located.
3. Make the script executable: chmod +x vagrant_box_updater.sh
4. Run the script: ./vagrant_box_updater.sh
@imranbhullar
imranbhullar / db_random.py
Last active June 16, 2019 02:57
This small python script will create 1million random numbers and push that to MySQL DB
#This small script will create 1million random numbers and push that to MySQL DB
import secrets
import pymysql
connection = pymysql.connect(host='dbserver.ourdomain.com',
user='dbuser',
password='dbpasswod',
db='DBNAME',
charset='charset',
port=3306,
cursorclass=pymysql.cursors.DictCursor)
@imranbhullar
imranbhullar / netscaler_pexpect.py
Created March 12, 2018 04:51
Using pexpect to play with network appliances e.g. netscaler
import pexpect
child = pexpect.spawn ('ssh username@xxx.xxx.xxx.xxx -o StrictHostKeyChecking=no')
child.expect ('Password:')
child.sendline('mysupersecret\n')
child.expect ('.*>')
child.sendline ('show Hostname\n')
child.expect('>')
print child.before
child.expect('>')
child.sendline ('set HostName EDGE-Device\n')
@imranbhullar
imranbhullar / mysql_pexpect.py
Created March 12, 2018 04:50
Using pexpect to play with mysql.
import pexpect
child = pexpect.spawn ('mysql -umyuser -pmysupersecret -hxxx.xxx.xxx.xxx')
child.expect ('mysql> ')
child.sendline ('show databases;\n')
child.expect ('mysql> ')
print child.before
child.expect('mysql> ')
child.sendline ('show processlist;')
child.expect ('mysql> ')
print child.before
@imranbhullar
imranbhullar / ftp_pexpect.py
Created March 12, 2018 04:49
using pexpect to play with FTP
import pexpect
child = pexpect.spawn ('ftp ftp.freebsd.org')
child.expect ('Name .*: ')
child.sendline ('anonymous')
child.expect ('Password:')
child.sendline ('me@mydomain.com')
child.expect ('ftp> ')
child.sendline('cd /pub/FreeBSD')
child.expect('ftp>')
child.sendline('get README.TXT')
@imranbhullar
imranbhullar / apache_log_parse_csv.py
Last active June 16, 2019 02:59
Parsing Apache logs to a CSV using python
#Parsing apache logs to a CSV using python
import csv
OutputCsv = open("/some/path/output.csv",'wb')
Writer = csv.writer(OutputCsv)
header = ['User Address', 'Date/Time', 'Action', 'Requested URL', 'Return Code', 'Size']
Writer.writerow(header)
f = open('/some/path/http_logs.log', 'r')
for line in f:
line = line.split()
line = line[0:4] + line[5:7]