linux
Categories:

Cron trick to run a job at 0:01 only the 1st Monday of the month:

    1 0 1-7 * * [ "$(date '+\%a')" == "Mon" ] && command

Adjust the DoM field for 7-day ranges for the 2nd, 3rd, etc... weeks.

Categories:

Advanced command history substitution

Execute previous command with a string replacement (only works on first string)

$ ls *.tmp

$ ^ls^rm
rm *.tmp

$ cp -i file1 file2 file3 destdir

$ ^-i    # no 2nd string replaces with nothing
cp file1 file2 file3 destdir

Replace all occurrences of string in previous command:

$ echo 4 4 4 4 4

$ !:gs/4/5/
echo 5 5 5 5 5

Access previous commands:

$ls -l *.txt

$ !!    # run the last command
ls -l *.txt

$ !-1    # same as !!
$ !-2    # run the command before the last one
$ !-3    # run the 3rd previous command

Access the parameters of the previous command:

$ cp file1 file2 file3 destdir

$ echo !$
destdir

$ echo !*
file1 file2 file3 destdir

Categories:

Wiping Free Space

Creates 1GB files full of zeros. Wipes almost all of the free space. Use a for loop to create the files on each filesystem. Run until the filesystem fills up before deleting zero files.

for (( i=1; i<=10; i++ ))
do
    num=$(printf "%03d" $i)
    echo $num
    dd bs=1024 count=1024K if=/dev/zero of=zero-$num
    sync
done

Wiping a Whole Drive

In RedHat Enterprise, and maybe others:

badblocks -w -s -p # [device]

Where # is the number of passes you want to use and device refers to the partition (/dev/sda1) or whole device (/dev/sda) you want to wipe.

Categories:

Linux/UNIX notes

Categories:

For testing out a new mail server, etc...

HELO mydomain.com
MAIL FROM: <from@mydomain.com>
RCPT TO: <user@server.com>
DATA
Subject: testing 123
To: <user@server.com>

This is a test message

.
QUIT

Categories:


#!/usr/bin/perl
# rexname - Larry's filename fixer
#
# Modified by Brian Mathis to add testing and verbose
#
use strict;
use Getopt::Long;

my $usage = < Usage:
rexname expr [files]
rexname --test expr [files]
rexname --verbose expr [files]

Options:
--test (-t)
Don't actually do anything (implies -v)

--verbose (-v)
Display output of changes as they are made
USAGE

my($test, $verbose);
GetOptions("test" => \$test, "verbose" => \$verbose);
if($test) { $verbose = 1; }

my $op = shift or die $usage;
chomp(@ARGV = ) unless @ARGV;
for (@ARGV) {
my $was = $_;
eval $op;
die $@ if $@;
print "$was \t-> $_\n" if $verbose;

Categories:

Used with cygwin. Helpful when using rxvt as the cygwin terminal.

xterm*foreground: gray
xterm*background: black
xterm*geometry: 132x50
xterm*saveLines: 1000
xterm*scrollBar: true
xterm*rightScrollBar: true
xterm*loginShell: true

rxvt*foreground: gray
rxvt*background: black
rxvt*geometry: 132x50
rxvt*saveLines: 1000
rxvt*scrollBar: true
rxvt*scrollBar_right: true
rxvt*loginShell: true
rxvt*font: DejaVu Sans Mono-13

Categories:
# Disable startup message
startup_message off

# Change scrollback to 10000 lines
defscrollback 10000

# status line at the bottom
caption always
caption string "%{.bW}%-w%{.rW}%f%n %t%{-}%+w %=%{..G}[%H %l] %{..Y} %m/%d %c "

# allow scrollback to work in terminal programs (like putty)
termcapinfo xterm ti@:te@