Skip to content

Instantly share code, notes, and snippets.

View compor's full-sized avatar

Chris Vasiladiotis compor

  • University of Edinburgh
  • Edinburgh, Scotland, UK
  • 21:15 (UTC +01:00)
View GitHub Profile
@compor
compor / bash_get_ethernet_if_name.sh
Created February 25, 2013 15:17
retrieves the name of the first ethernet interface
ifconfig -a | grep -i "link[ ]*encap[ ]*:[ ]*ethernet" | awk 'BEGIN{ iface="z" }
{ if( $1 ~ /^eth/ && iface > $1 ) iface=$1 }
END{ print iface }'
@compor
compor / bash_create_multiple_screen_sessions.sh
Created February 25, 2013 15:19
create multiple screen session for a specific function
#!/bin/bash
#
# it starts multiple screen session whose usual task is remote ssh over
# a line separated list of IP's
# session_name : the prefix of the name of the screen sessions
# script_name : implements the remote ssh code e.g. with python's paramiko
# input_file_prefix : the prefix of the files for the script to process
# iterations : the number of input files which is equivalent to the screen sessions to be spawned (indexing is zero-based)
#
@compor
compor / bash_x11_fwd_enable_disable.sh
Created February 25, 2013 15:19
enable/disable SSH X11 forwarding
#!/bin/bash
SSHD_CONFIG=/etc/ssh/sshd_config
SSH_SVC=/etc/init.d/sshd
v=`grep -m 1 -e "X11Forwarding" ${SSHD_CONFIG} | awk '{ if( $0 ~ /^#/ ) print "no"; else print $2; }'`
enabled=0;
if [ ${v} == 'yes' ]; then
@compor
compor / bash_tcp_retransmission_checker.sh
Created February 25, 2013 15:22
tcp retransmission checker
# the capture file should be filtered in order to contain
# 1] the source address of the host for which we are checking the re-transmission mechanism for
# 2] and the destination should be any number of target hosts we are interested in
# 3] we only need the retransmitted packets (apply appropriate filter)
# 4] the capture file to be processed should be exported in text format with as much verbose info as possible
# script 1
# splits the capture in separate files (using a specific prefix) each containing a separate re-transmission stream - identified by the same destination IP and the same TCP sequence port
#!/bin/bash
@compor
compor / bash_dir_name_cleanup.sh
Created February 25, 2013 15:23
directory filename cleanup
# 1] convert all to lowercase letters
convmv --lower --notest *
# 2] remove naming defects such as :
# a] consecutive spaces
# b] weird characters like commas, parentheses, underscores, etc
@compor
compor / bash_convert_delicious_tags.sh
Created February 25, 2013 15:24
convert delicious tags from space-separated to comma-separated
# delicious decided (out of nowhere) to change its tag separator from whitespace to comma,
# but since it didn't update it's browser plugin, i ended up with messed up multi-word tags
# here's my quick solution to fix that mess :
#
# 1] export all your delicious tags to a html file e.g. delicious.html
# 2] execute the below awk script to the exported file
BEGIN{ FS = "=" }
{
@compor
compor / bash_route_blackhole.sh
Created February 26, 2013 10:39
null/blackhole route
# network route that goes nowhere - blackhole filtering
# 1] available to almost every host implementing the ip module
# 2] almost 0 performance impact
# 3] can sustain higher throughput than conventional firewalls
route add -host 192.168.1.1 reject
@compor
compor / bash_trap_control.sh
Created February 26, 2013 11:18
trap control in bash
#!/bin/bash
# http://hacktux.com/bash/control/c
cleanup()
# example cleanup function
{
rm -f /tmp/tempfile
return $?
}
@compor
compor / bash_add_delete_crontab_entry.sh
Created February 26, 2013 11:33
add/remove crontab entry
#!/bin/bash
# it can add/delete multiple times the same crontab entry
# without having to worry for duplicate entries (in case of adding)
# or any leftovers (in case of deleting)
# THIS KEY HAS TO BE UNIQUE IN THE ENTRY TO BE ADDED/DELETED
CMD_KEY="moo"
@compor
compor / session_spawner.py
Last active December 14, 2015 05:49
spawns multiple screen session for simultaneous command execution
#!/usr/bin/env python
import sys
import os
import traceback
from optparse import Option, OptionParser, OptionGroup
version_string = "\n\
%prog\n"