SSH Agent Forwarding for "sudo su"

Exporting of SSH_AUTH_SOCK environment variable when using sudo su enables forwarding of user's SSH agent connection to root environment
(umask 0440; echo 'Defaults env_keep += "SSH_AUTH_SOCK"' > /etc/sudoers.d/ssh-auth-sock)
Example of using /etc/sudoers.d/ssh-auth-sock on host machine. The example assumes that the user copied already their public SSH key to the destination machines under root user:
$ ssh -A user@host
[user@host]$ sudo su
[root@host]# ssh remote
[root@remote]#

dos2unix & unix2dos

Convert file with Windows line endings to UNIX and vice versa, all in Perl:
perl -i -pe 's/\r//g' dos2unix
perl -i -pe 's/\n/\r\n/g' unix2dos

GRUB2 Multiboot USB Stick

Booting SystemRescudeCd and Windows 7 Installation from a USB stick using GRUB2. Assuming that /dev/sdb1 is an NTFS formated partition mounted under /mnt/usb:
  1. Copy the whole content of Windows 7 DVD directly into /mnt/usb.
  2. Copy sysrcd.dat, sysrcd.md5, isolinux/initram.igz and isolinux/rescue64 from SystemRescudeCd ISO image into /mnt/usb/linux.
  3. Install GRUB2 to the USB stick:
    grub-install --no-floppy --root-directory=/mnt/usb /dev/sdb
    
  4. Edit /mnt/usb/boot/grub/grub.cfg, e.g.:
    set timeout=5
    set default=0
    
    menuentry "System Rescue CD 64bit" {
            linux /linux/rescue64 subdir=linux scandelay=1 docache nomodeset
            initrd /linux/initram.igz
    }
    
    menuentry "Windows 7 Installation" {
            ntldr /bootmgr
    }
    

Ping

ICMP echo request alias ping:
perl -MNet::Ping -lne 'print "$_: ", scalar Net::Ping->new( "icmp" )->ping( $_ )' hosts.txt
TCP based ping using port 80:
perl -MNet::Ping -lne '$p = Net::Ping->new; $p->port_number( 80 );
                       print "$_: ", scalar $p->ping( $_ )' hosts.txt

Blocking Traffic Using Null Route

Blocking network traffic for a specific host without using iptables:
ip route add blackhole 10.0.0.1/32
To remove the rule:
ip route del blackhole 10.0.0.1/32
Compared to iptables a null route has no effect on loopback addresses (127.0.0.0/8).

Erase Old Files

Erase files older than 7 days:
find -mtime +7 -exec rm -rf {} \;

Git Tagging

Add an annotated tag:
git tag -a v1.0.0 -m 'release 1.0.0'
Push tag changes to remote repositories:
git push --tags
Remove a tag:
git tag -d v1.0.0
Remove a tag from remote repositories:
git tag -d v1.0.0
git push origin :refs/tags/v1.0.0

Advanced Netstat

Display all TCP and UDP connections with DNS names, numeric ports and program name:
netstat -tuap --numeric-ports

WAV to FLAC

find -name \*.wav -exec flac --best '{}' \;

Raw Partition as VirtualBox Disk

Lists all partitions on /dev/sda:
VBoxManage internalcommands listpartitions -rawdisk /dev/sda
Create a VMDK image to access the first partition in raw mode, e.g.:
VBoxManage internalcommands createrawvmdk \
           -filename sda1.vmdk -rawdisk /dev/sda -partitions 1 -relative
Grant read and write access to the raw partition, e.g.:
setfacl -m g:vboxusers:rw /dev/sda1

Disk Info

hdparm -I /dev/sda

Generating Series of Random Samples in PostgreSQL

An output example:
"2012-01-01 00:00:00";91.66
"2012-01-01 00:05:00";23.71
"2012-01-01 00:10:00";32.61
...
"2012-01-01 23:55:00";86.62

wget like cURL

Use curl like wget:
alias cget='curl -LOR --insecure'
cget https://foo.bar.com/file.tar.xz

PostgreSQL CSV Like Output

Use -t (--tuples-only), -A (--no-align) and -F (--field-separator) to generate CSV like output, e.g.:
psql postgres -tAF, -c'select name, abbrev from pg_timezone_names'

Microphone to Speakers

On the fly playing of captured microphone sound:
arecord | aplay

Colors in grep

Enable color output for grep using an environment variable or on demand:
export GREP_OPTIONS='--color=auto'
grep --color=auto foo bar

Screen Ultimate Attach

Screen Quick Reference: Attaches to a screen session. If the session is attached elsewhere, detaches that other display. If no session exists, creates one. If multiple sessions exist, uses the first one:
screen -dRR

Pure Perl Configuration File

A safe way of loading configuration settings stored as a Perl hash:

Completely Clear Bash History

history -c; rm -f ~/.bash_history

Simple SNMP Trap Testing

Start a non forking snmptrapd daemon accepting all incoming traps and logging them to standard output:
snmptrapd -CdfLo --disableAuthorization=yes
Send a testing trap to the host running snmptrapd daemon (in this example 10.0.0.1):
snmptrap -v 1 -c public 10.0.0.1 .1.3.6.1.6.3 "" 0 0 coldStart.0
Also make sure the host firewall is not blocking incoming UDP/162 traffic.