Răzvan Cosma's scratchpad

random scripts of random value


%pre --interpreter=busybox
# extract network info from bootup
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}')
HOSTNAME=$(nslookup "${IPADDR}" "${DNS}" | grep Address | grep "${IPADDR}" | awk '{print $4}')
echo "network --bootproto=static --addvmportgroup=true --device=vmnic0 --ip=${IPADDR} --netmask=${NETMASK} --gateway=${GATEWAY} --nameserver=${DNS} --hostname=${HOSTNAME}" > /tmp/networkconfig


$int1 = Get-WmiObject -Query "select * from Win32_networkadapterconfiguration where dhcpenabled = true and ipenabled = true" | select-object -first 1
$int2 = Get-WmiObject -Query "Select * from Win32_NetworkAdapter where MACAddress = '$($int1.MACAddress)'"
write-host $($int1.IPAddress[0]), $($int1.IPSubnet[0]), $($int1.DefaultIPGateway[0]), $($int2.NetConnectionID), $($int1.DNSServerSearchOrder[0])
&netsh interface ipv4 set address `"$($int2.NetConnectionID)`" static $($int1.IPAddress[0]) $($int1.IPSubnet[0]) $($int1.DefaultIPGateway[0])
&netsh interface ipv4 add dnsservers `"$($int2.NetConnectionID)`" $($int1.DNSServerSearchOrder[0]) validate=no
&netsh interface ipv4 add dnsservers `"$($int2.NetConnectionID)`" $($int1.DNSServerSearchOrder[1]) index=2 validate=no

ll /var/adm/ras/bosinstlog

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;}
ll /dev/config
echo "sel dev 1;info;wait;il"|/usr/sbin/cstm

rpm -qi basesystem
rpm -qi filesystem
head /var/log/installer/syslog

ll /var/sadm/system/logs
/usr/sbin/prtconf | head

systeminfo | findstr Original

$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
  write-host $pages
} finally { $word.Quit() }

If (New-Object System.Net.Sockets.TCPClient -ArgumentList '',1688) {Write-Host 'YES'}

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
continue reading…

For want of a proper sed, the PS way:
Get-ChildItem -exclude *bak | Where-Object {$_.Attributes -ne “Directory”} | ForEach-Object { Copy-Item $_ “$($_).bak”; (Get-Content -Encoding UTF8 $_) -replace “some text”,”other text” | Set-Content -Encoding UTF8 -path $_ }

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 { $_, 1 } @ports; @ports=keys %h; $apps{$p}->{"ports"}=join(", ",@ports); close(F);
foreach $p (sort {$apps{$a}->{"cmd"} cmp $apps{$b}->{"cmd"}} keys %apps) {
printf("%-5s %-30.32s\t%-20s\n",$p,$apps{$p}->{"cmd"},$apps{$p}->{"ports"}) if length($apps{$p}->{"ports"})>0;
continue reading...

# mencoder infile.avi -ovc lavc -oac copy -lavcopts vcodec=mpeg4:threads=2:autoaspect:turbo:mbd=2:trell=1 -ffourcc xvid -mc 0 -vf softskip,harddup -o outfile.avi

sysprep -pnp -mini -reinstall -nosidgen -reseal -forceshutdown

.. 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
on t.object_id=c.object_id
where c.name like '%dns%'
order by sname, tname
EXEC SearchTables @Tablenames = '%',@SearchStr = 'host%'

continue reading…

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