Skip to content

Instantly share code, notes, and snippets.

@brianz
Last active August 11, 2016 04:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianz/deb45115a8b09704c8d4beee38af3104 to your computer and use it in GitHub Desktop.
Save brianz/deb45115a8b09704c8d4beee38af3104 to your computer and use it in GitHub Desktop.
brianz's tech scratch pad

Sum column using awk

cat count.txt | awk '{sum+=$1} END {print sum}'

List open ports

linux: netstat -lnptu
mac: netstat -a -p tcp

Find what is listening on a port

lsof -Pnl +M -i4

Reset postgres pkey sequences

SELECT pg_catalog.setval(pg_get_serial_sequence('TABLE_NAME', 'id'), (SELECT MAX(id) FROM TABLE_NAME)+1);

List connected hosts

netstat -n -A inet
netstat -n -A inet | awk '{print $5}' | tr ':' ' ' | awk '{print $1}' | sort | uniq -c

DNS Stuff

dscacheutil -q host -a name admin.ccdev.vg
scutil --dns

In-place replacement

find . -name '*.py' -exec sed -i '' -e  "s/OLD_PATTERN/NEW_PATTERN/g" {} \;

Add/remove users into/out of groups

usermod -a -G GROUP_NAME USER_NAME
usermod -G "" USER_NAME

Read an SSL certificate

openssl x509 -in public.pem -text -noout

Execute a command for a user who has no login shell

su -s /bin/bash -c '/path/to/your/script' testuser

Remove virtual box virtual interfaces

VBoxManage hostonlyif remove vboxnet1

Purge all queues from rabbitmq

for q in ` sudo rabbitmqctl list_queues | awk '{print $1'} | egrep "d16|celery"`;
     do celery amqp queue.purge $q;
done

Display status of loaded kernel extensions

man kextstat
kextstat | grep -i usb  | awk '{print $6}' | sort

Display the system message buffer

dmesg

Setup vim plugins

https://github.com/tpope/vim-pathogen

Push up to a specific commit

git push origin SHA:branch_name

Run a simple HTTP server using nc

nc -kl 5432 -c 'echo -e "HTTP/1.1 200 OK\r\n$(date)\r\n\r\n";echo "<p>How are you today?</p>"'
while true ; do nc -l 80  < index.html ; done

Find time a process has been running

for pid in `ps auwwwx | grep uwsgi | grep clearcare.yaml | awk '{print $2}'`; do
  ps -p $pid -o etime=
done

Add/remove 200ms delay to a network interface

root@ccdev# tc qdisc add dev lo root netem delay 200ms
root@ccdev# tc qdisc del dev lo root

Correct perms for ssh files/dirs

chmod 700 /home/your_user/.ssh
chmod 600 /home/your_user/.ssh/authorized_keys

Get IP address for a given network device

ifconfig eth1 | grep "inet addr" | awk '{ print substr($2,6) }

ssh-agent on the mac

sudo launchctl load -w /System/Library/LaunchAgents/org.openbsd.ssh-agent.plist
sudo launchctl unload /Path

To start a differently named key at login:

ssh-add -K ~/.ssh/some_key

Strip multiple characters with sed

sed 's/[<>,]//g'

Default a command line arg in bash

FOO=${VARIABLE:-default}

Patching in Git

git apply --check tests.patch
git apply -v --check tests.patch to see where it's blaring

Getting LOC changed in a commit range

git log --author=Brian --since="Feb 15, 2014" --no-merges --numstat --pretty="%H" -- tests | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'

OS X

sudo killall -HUP mDNSResponder

Ubuntu

Uninstall and purge a debian pakages…removes conf files: dpkg -P elasticsearch Install a package from a file: dpkg -i elasticsearch-0.90.7.deb

Reset guest additions version

VBoxManage guestproperty set ae63d283-bd8d-44ea-be05-e61c9b2a8f73  /VirtualBox/GuestAdd/Version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment