Wednesday, August 13, 2014

/etc/acct/holidays

In /var/adm/messages on Solaris:

Aug 13 02:30:16 hostname adm: [ID 702911 daemon.notice]
Aug 13 02:30:16 hostname last message repeated 4 times
Aug 13 02:30:16 hostname adm: [ID 702911 daemon.notice] **********  SYSTEM ACCOUNTING STARTED Wed Aug 13 02:30:16 BST 2014  **********
Aug 13 02:30:16 hostname adm: [ID 702911 daemon.notice]
Aug 13 02:30:16 hostname last message repeated 4 times
Aug 13 02:30:16 hostname adm: [ID 702911 daemon.error]
Aug 13 02:30:16 hostname last message repeated 1 time
Aug 13 02:30:16 hostname adm: [ID 702911 daemon.error] ************ ACCT ERRORS : see  /var/adm/acct/nite/log********
Aug 13 02:30:16 hostname adm: [ID 702911 daemon.error]
Aug 13 02:30:16 hostname last message repeated 1 time

In /var/adm/acct/nite/log

***UPDATE /etc/acct/holidays WITH NEW HOLIDAYS***

Update /etc/acct/holidays to have 2037 for the year.

$ cat /etc/acct/holidays
* @(#)holidays  January 1, 2010
*
* Prime/Nonprime Table for UNIX Accounting System
*
* Curr  Prime   Non-Prime
* Year  Start   Start
*
  2037  0800    1800
*
* only the first column (month/day) is significiant.
*
* month/day     Company
*               Holiday
*
1/1             New Years Day
12/25           Christmas

https://hg.openindiana.org/upstream/illumos/illumos-gate/raw-file/afe390b9f1e0/usr/src/cmd/acct/lib/pnpsplit.c

/*
 * inithol - read from an ascii file and initialize the "thisyear"
 * variable, the times that prime and non-prime start, and the
 * holidays array.
 */
int
inithol()
{
...
 /* validate year */
 if(thisyear < 1970 || thisyear > 2037) {
  fprintf(stderr, "pnpsplit: invalid year: %d\n",
   thisyear);
  errflag++;
  break;
 }
...
}

Thursday, July 17, 2014

To replace text in vim with line number

e.g.:
mv file_abc.jpg pic.XX.jpg
mv random.jpg   pic.XX.jpg
mv other.jpg    pic.XX.jpg
mv name.jpg     pic.XX.jpg
If you do this:
:%s/XX/\=line(".")/

Tuesday, July 01, 2014

Make SSH ignore SSH key

Make SSH ignore your SSH key, not prompt for a passphrase, only use password:

$ ssh -o PreferredAuthentications=keyboard-interactive -o PubkeyAuthentication=no destination.host

Wednesday, May 28, 2014

find things...

Find files that are not world readable and make them readable:

sudo find . -type f \! -perm -4 -exec chmod o+r {} +

Find files that are not group readable

find . -type f \! -perm -40 -ls

Find files that are group writable

find . -type f -perm -20 -ls

Find files that are world writable

find . -type f -perm -2 -ls

Wednesday, May 14, 2014

To find if a Solaris host is running on an LDom

If the file /usr/sbin/virtinfo exists, run:

$ /usr/sbin/virtinfo -a

If you run it as root it will also tell you the hostname of the Control domain and the Chassis serial#.

Thursday, November 14, 2013

list to csv...

ls | paste -s -d'%' - | sed 's/\(^\|$\)/"/g;s/%/","/g'

Friday, October 11, 2013

web client in pure bash

( printf "GET /path/to/file HTTP/1.0\n\n" 1>&0 ; cat ) 0<> /dev/tcp/<HOSTNAME>/80
Thanks David!

Tuesday, August 13, 2013

Get Windows hostname from IP address via Samba

You can tell it's likely to be a Windows box by what ports it has open...

"The target host OS can often be guessed simply by looking at the ports which are open. Microsoft Windows machines often have TCP ports 135 and 139 open. Windows 2000 and newer also listen on port 445." ( from: http://nmap.org/book/osdetect-other-methods.html )

Once you've identified it's a Windows host, how can you tell which one?

Try this:

$ nmblookup -A 12.34.56.78
Looking up status of 12.34.56.78
        HOSTNAME        <00> -         M <ACTIVE>
        DOMAINNAME      <00> - <GROUP> M <ACTIVE>
        HOSTNAME        <1f> -         M <ACTIVE>
        HOSTNAME        <20> -         M <ACTIVE>
        DOMAINNAME      <1e> - <GROUP> M <ACTIVE>

        MAC Address = 00-11-22-33-44-55

Tuesday, August 06, 2013

swap usage...

To find out how much swap processes are using...

On Solaris:

ps -eo vsz,rss,pid,args | sort -n top -b -o size

Total swap used by pid

pmap -S $PID | tail -1 | awk '{print $4}'
20236


Don't really want to use these:

prstat -s rss
prstat -s size


Size: total virtual memory size of the process, including all mapped files and devices.
RSS: should be the resident set size, but is completely unreliable.

On Linux:


#!/usr/bin/perl -s

use warnings;
use strict;

if ( $< != 0 ) {
    die "ERROR: $0 Needs to be run as root\n";
}
our ($c,$m,$n,$t);

opendir(my $proc,"/proc");

my $pids;
my $total;

for my $pid (grep {/^[0-9]+$/} readdir($proc)) {

    #
    # If the process has terminated already, skip on to the next one.
    #
    open(my $smaps, "/proc/$pid/smaps") || next;
    while(<$smaps>) { next if !/^Swap:\s+(\d+) kB$/; $pids->{$pid}->{swap} += $1; }
    close($smaps);

    if ( $pids->{$pid}->{swap} ) {

        open(my $cmdline, "/proc/$pid/cmdline");
        while(<$cmdline>) { s/\0/ /g; $pids->{$pid}->{cmdline} = $_; }
        $total += $pids->{$pid}->{swap};

    } else {

        delete $pids->{$pid};

    }

}

if ( $c && ! $n ) {
    print "  PID   Swap Cmd\n";
}
for my $pid ( sort { $pids->{$b}{swap} <=> $pids->{$a}{swap} } keys %$pids ) {

    # Only report procs > 1MB
    next if $pids->{$pid}->{swap} < 1024;
    # Specify minimum size (MB) to report
    # print "m [$m] swap[$pids->{$pid}->{swap}]\n";
    next if ( $m && $pids->{$pid}->{swap} < $m * 1024 );
    if ( $c ) {
        printf "%5d %4dMB %s\n", $pid, $pids->{$pid}->{swap} / 1024, $pids->{$pid}->{cmdline};
    } else {
        printf "%5d %4dMB\n", $pid, $pids->{$pid}->{swap} / 1024;
    }

}

if ( $t ) {
    printf "Total: %dMB\n", ${total} / 1024;
}

Monday, July 08, 2013

Copy history from one git repo to another

cd repository
git log --pretty=email --patch-with-stat --reverse -- path/to/file_or_folder > ../patch
cd ../other_repository
git am < ../patch