Wednesday, December 19, 2012

Sometimes when you want to do something on the web, they insist you give an email address to sign up.

Many of them won't accept addresses from

https://www.guerrillamail.com/

But they MAY accept addresses from:

http://www.mailexpire.com/

easy... just point a mailexpire address at a guerrillamail account...

Job done! :-)

Friday, December 14, 2012

VBS script to launch multiple PuTTY sessions

This is to launch parallel PuTTY sessions to a list of hosts, as by the name of their saved PuTTY sessions.

Set objShell = CreateObject("WScript.Shell") dim hosts hosts = "host1 host2 host3 host4" dim host for each host in split(hosts) objShell.Exec "C:\Program Files\PuTTY\PUTTY.EXE -load " + host next

NB: you could use

objShell.Exec "C:\Program Files\PuTTY\PUTTY.EXE username@" + host

instead of

objShell.Exec "C:\Program Files\PuTTY\PUTTY.EXE -load " + host

If you want to log straight into the box without using a saved session

Monday, December 03, 2012

bash command history elements

While you can do

<command> !$

To reuse the last argument of the previous command, you can also use !:n to get the n'th word from the previous command line.

!:0 is the command, the arguments start at index 1.

!* gives ALL of the arguments without the command.

Thanks larsmans & Gilles

Tuesday, October 09, 2012

Solaris x86 serial numbers

$ ipmitool fru

Invalidate nscd cache

If you want nscd to forget a database, you can invalidate it so that it gets reloaded next time you query it.

Use:

nscd -i <database>

e.g.:

nscd -i passwd

Wednesday, August 08, 2012

Adding an ACL with chmod

chmod A+user:$USER:write_attributes/write_acl:allow $FILENAME

Look at http://www.cuddletech.com/blog/pivot/entry.php?id=939 for more.

The secret is in the +
Use:

ls -v(a)

To show the existing ACL.

Thursday, May 24, 2012

Jump to column in vi

You can jump to a line in vi with <line number>G

To jump to a column on the current line, use <column number>| (pipe character)

Friday, May 11, 2012

Add line after match using ex

This little script is to append a line to a file after a text match, using ex.

This particular one is for /usr/local/etc/sudoers to add a 5 minute timeout to the root sudo.

#!/bin/bash FILE=$1 cp -p $FILE $FILE.old ex $FILE <<EOT /^User_Alias.*UNIX.*wheel a Defaults:UNIX timestamp_timeout=5 . x! EOT

Friday, February 03, 2012

Simple password generator

This generates shadow file entries with MD5 crypted passwords.

If you don't specify a password to use on the command line, it will generate a random 15 character password for you.

NB: You really shouldn't use it with a password on the command line, as this can be seen by other users with the ps command while it's running. I've just done this to simplify the example. This code is a snippet, intended to be used in a larger script where the password would be read from a file or provided on STDIN.


#!/usr/bin/perl
#
#
#
use warnings;
use strict;

my $len = 15;

my $plaintext = shift;
if ( ! $plaintext ) {

    my @chars;
    for my $char (33 .. 126) {
        push @chars, chr($char);
    }
    for (1..$len) {
        $plaintext .= $chars[int(rand($#chars))];
    }

}

my @schars = ('a'..'z','A'..'Z',0..9,'.','/');
my $salt = '';
for (1..8) {
    $salt .= $schars[int(rand($#schars))];
}
my $crypted_pass = crypt($plaintext,'$1$' . $salt )
    or die($!);

print "$plaintext\n$crypted_pass\n";


There are other tools to do this.

For example, on Debian Linux so far I know of:


$ dpkg -S /usr/bin/openssl
openssl: /usr/bin/openssl
$ dpkg -S /usr/bin/mkpasswd
whois: /usr/bin/mkpasswd
$ dpkg -S /usr/bin/makepasswd
makepasswd: /usr/bin/makepasswd


Usage:


$ openssl passwd -1 -stdin <<EOT
passwd
EOT
$1$nRGcgK4T$uI7mxwMxGUt6NQ.lyu42./
$ mkpasswd -5 -s <<EOT
> passwd
> EOT
$1$0rg1g/e9$rh1lfYHX9qkSVihZ9vBcd/
$ makepasswd --crypt-md5 --clearfrom=-
passwd
passwd $1$IEK./reC$UbqosXZvVn6Hv/2Zej.va/


I wanted to run it on Solaris, and I wanted to run it in a Perl program (because the rest of the program I was writing was in Perl)

The openssl and mkpasswd programs are compiled C binaries, makepasswd is written in Perl, but it uses Crypt::OpenSSL::Random to generate better randomness, and the box I needed to run it on didn't have that library.

I expect the rand() in Perl is quite random enough for my needs here!

Thursday, February 02, 2012

Yesterday...

You can get yesterday's date with


$(TZ=GMT+24 date +%y%m%d)


(or tomorrow's with -24)