convert DHCP IP to static

ESXi %pre –interpreter=busybox # extract network info from bootup VMK_INT=”vmk0″ VMK_LINE=$(localcli network ip interface ipv4 get | grep “${VMK_INT}”) IPADDR=$(echo “${VMK_LINE}” | awk ‘{print $2}’) NETMASK=$(echo “${VMK_LINE}” | awk ‘{print $3}’) GATEWAY=$(esxcfg-route | awk ‘{print $5}’) DNS=”172.16.0.1″ HOSTNAME=$(nslookup “${IPADDR}” “${DNS}” | grep Address | grep “${IPADDR}” | awk ‘{print $4}’) echo “network –bootproto=static –addvmportgroup=true –device=vmnic0 […]

Figure out when a system was installed

AIX: lsconf ll /var/adm/ras/bosinstlog ESXi: get-vmhost | sort name | foreach {$h = $_.Name; $d = (Get-EsxCli -VMHost $h).software.vib.list() | sort InstallDate | select -first 1; write-host $h,$d.InstallDate;} HP-UX: ll /dev/config echo “sel dev 1;info;wait;il”|/usr/sbin/cstm Linux: rpm -qi basesystem rpm -qi filesystem head /var/log/installer/syslog Solaris: showrev ll /var/sadm/system/logs /usr/sbin/prtconf | head Windows: systeminfo | findstr […]

count pages for all docs in a folder

$word = New-Object -ComObject word.application $word.visible = $false $pages = 0 try { Get-ChildItem -path “.” | ? {$_.name -match “.*\.docx{0,1}$”} | foreach-object { write-host $_.name # fullName, confirmConversion, readOnly, addToRecent, passwordDocument $doc = $word.documents.open($_.fullname, $false, $true, $false, “”) $window = $doc.ActiveWindow; $panes = $window.Panes; $pane = $Panes.item(1) $pages += $pane.pages.count $doc.close() write-host $pages } […]

increase kvm guest disk

1. add DAG repo 2. yum install libguestfs-tools 3. virt-filesystems –long –parts –blkdevs -h -a w2k8.img (the Windows C: is usually /dev/sda2) 4. dd if=/dev/zero of=w2k8new.img seek=20000 bs=1M count=1 5. virt-resize –expand /dev/sda2 w2k8.img w2k8new.img

Solaris – what process is listening on each port?

Since Solaris doesn’t have a ‘netstat -tunlp’, the below parses the output of ptree and pfiles to get a list: my %apps; open(T, “ptree |”); while() { $apps{$1}->{“cmd”}=$2 if(/(\d+)\s+(.*)/) }; close(T); foreach my $p (sort keys %apps) { my @ports; open(F, “pfiles $p 2>/dev/null |”); while() { push(@ports,$1.”/”.$2) if(/sockname.*?AF_INET[6?]\s+(.*?)\s+port: (\d+)/) } my %h=map { $_, […]

hunting for a random string

.. in a large (and completely undocumented) database, I’ve found the ways to get all tables that have a column name like ‘string’ and all rows that contain a string. A bit more optimized than my previous search&replace example. select t.name as tname, SCHEMA_NAME(schema_id) as sname, c.name as cname from sys.tables t join sys.columns c […]

Bad Behavior has blocked 204 access attempts in the last 7 days.