Skip to content

Instantly share code, notes, and snippets.

View shoaibi's full-sized avatar

Shoaibi shoaibi

View GitHub Profile
@shoaibi
shoaibi / clear-iptables.sh
Created June 25, 2015 15:34
Sweep iptables rules
#!/bin/sh
# Must run as root.
echo "Stopping firewall and allowing everyone..."
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
@shoaibi
shoaibi / git-mv-branch.sh
Created June 25, 2015 15:34
Rename a git branch
#!/bin/bash
E_BADARGS=65
if [ $# -ne 2 ]; then
echo "Usage: $0 {old_branch_name} {new_branch_name}"
exit $E_BADARGS
fi
old_branch="$1"
new_branch="$2"
@shoaibi
shoaibi / git-rm-branch.sh
Created June 25, 2015 15:35
Remove a git branch
#!/bin/bash
origBranch=$(git rev-parse --abbrev-ref HEAD)
delBranch="$1"
E_BADARGS=65
if [ $# -ne 1 ]; then
echo "Usage: $0 {branch_name}"
exit $E_BADARGS
fi
@shoaibi
shoaibi / git-update-origin.sh
Created June 25, 2015 15:37
Update git repository's origin
#!/bin/bash
origBranch=$(git rev-parse --abbrev-ref HEAD)
upstreamBranch="$origBranch"
E_BADARGS=65
if [ $# -ne 2 -o $# -ne 1 ]; then
echo "Usage: $0 {new_origin} [{upstreamBranch}]"
exit $E_BADARGS
elif [ "x$2" != "x" ]; then
upstreamBranch="$2"
@shoaibi
shoaibi / create_database_user.sh
Created June 25, 2015 15:45
Create a database and user
#!/bin/bash
#
# While working with webapps I found myself creating the database credentials
# as well as the databases over and over. For me the username to connect to
# database was always same as the database name, almost always. So I created
# the following script to help me quickly setup the credentials
#
# Ways you can use it:
# $0 secret
# In this case database's name, user's name and password
@shoaibi
shoaibi / cert-helper.sh
Created June 25, 2015 15:47
Generate ssl key, csr or self signed crt with one command
#!/bin/bash
#
# Just a clumsy little cert helper I use oftenly
#
#
E_BADARGS=65
if [ $# -lt 3 -o $# -gt 11 ]; then
echo "Usage: $0 mode[=key|csr|crt] name keyLength[=4096] commonName organizationUnit organization locality state countryTwoLetterCode emailAddress days[=1900]"
exit $E_BADARGS
@shoaibi
shoaibi / download-install-magento.sh
Created June 25, 2015 15:49
Download and install magento
#!/bin/bash
clear
stty erase '^?'
installSampleData=1
installExtensions=0
downloader="aria2c"
baseDownloadUrl="http://www.magentocommerce.com/downloads/assets"
magentoVersion="1.9.0.0"
magentoName="magento-${magentoVersion}"
@shoaibi
shoaibi / url-monitor.php
Created June 25, 2015 15:55
A simple url monitor that monitor the status of the url and search the page for provided string, sends email notifications if the check fails
#!/usr/bin/php
<?php
// Use https://uptimerobot.com/ instead
define('CONTACT_TO', 'me@my.com');
define('CONTACT_FROM', 'report@my.com');
$message = '';
$subject = '';
if (count($argv) > 3)
@shoaibi
shoaibi / offsite-mysql-backup.sh
Created June 25, 2015 16:21
Backup a mysql database and scp it to an offsite box.
#!/bin/bash
#
#
# Take dump of the configured database and transfer it to an offsite server
#
start_date=`date +M%m-D%d-Y%Y_%Hh%Mm%Ss`
source_db_user="sourceDatabaseUserNameHere"
source_db_password="sourceDatabaseUserPasswordHere"
@shoaibi
shoaibi / drop-or-truncate-db-tables.sh
Last active August 29, 2015 14:23
Drop or truncate tables in a mysql database
#!/bin/bash
MDB="$1"
KEYWORD="$2"
# Detect paths
MYSQL=$(which mysql)
AWK=$(which awk)
GREP=$(which grep)
E_BADARGS=65