Useful things to remember:
Send email via telnet
HELO example.com
MAIL FROM: user@example.com
RCPT TO: otheruser@example.com
RCPT TO: anotheruser@example.com
DATA
From: spammer@example.com
To: people@example.com
Subject: spam alert
Buy my crappy product!!
only $19.95
Get the version of sendmail
/usr/lib/sendmail -d0 < /dev/null | grep -i version
Use Perl to edit a file in place
perl -p -i -e "s#/etc#/u/decandia/dns-parsing-test#" zonefilenamehere
Redirect STDERR and STDOUT to a file
(uname -n;uname -xerror) > file.out 2>&1
clear the sendmail queue
/usr/lib/sendmail -q -v (all messages)
/usr/lib/sendmail -qI (specific queueID)
/usr/lib/sendmail -qR (specific recipient)
/usr/lib/sendmail -qS (specific sender)
/usr/lib/sendmail -L sm-msp-queue -Ac -q1m (clientmqueue)
Use awk to sum data
awk '{SUM=$5+SUM} END {print SUM,"in kbytes"}' < datafile
Override an ActiveRecord accessor method
class Ipinterface < ActiveRecord::Base
def macaddress=(macaddr)
super(Ipinterface.sanitize_macaddress(macaddr))
end
def macaddress
Ipinterface.sanitize_macaddress(super)
end
def Ipinterface.sanitize_macaddress(macaddr)
# Take a MAC address that looks like:
# 0:14:4f:8b:7:ba
# and convert it to
# 00:14:4f:8b:07:ba
split_mac = macaddr.split(/:/)
adjusted_mac = Array.new
split_mac.each do |bytes|
adjusted_mac << bytes.rjust(2,"0")
end
adjusted_mac.join(':')
end
end
Set up SSH port forwarding through an intermediary host
[user1@server:~]$ ssh -L8080:remotehost:8080 user1@jumphost
Make your xterm scrollbar work with screen
Add "termcapinfo xterm ti@:te@" to your ~/.screenrc file.
Set up a screen multiuser session
[user1@server:~]$ screen
Inside the screen session type:
Ctrl-A:multiuser on
Ctrl-A:acladd user2 [crypthash]
[user2@server:~]$ screen -rx user1/
Copy the whole screen scroll buffer to a file
Inside the screen session type:
Ctrl-A:hardcopy -h dump_file