Răzvan Cosma's scratchpad

random scripts of random value

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…

While dd / partimage might work just fine, these steps detail exactly what data is where and how it got to the disk during install. Assuming old=sda new=sdb

  1. fdisk -ucl /dev/sda, create identical ones on sdb, I’ll assume just a small ext4 sdb1 for boot and LVM sdb2 that fills the disk
  2. pvdisplay && pvcreate /dev/sdb2
  3. vgdisplay && vgcreate rootvg /dev/sdb2 -s 32M
  4. lvdisplay &&  lvcreate -L 300G -n rootlv rootvg
  5. mkfs.ext4 /dev/sdb1
  6. mkfs.ext4 /dev/mapper/rootvg-rootlv
  7. optional tune2fs -c 0 -i 0 /dev/mapper/rootvg-rootlv
  8. mount /dev/sdb1 newboot && mount /dev/mapper/rootvg-rootlv newroot
  9. rsync -aADHvxX /boot/ newboot/
  10. rsync -aADHvxX / newroot/
  11. rsync -aADHvxX /dev/ newroot/dev/
  12. blkid /dev/sdb1, write the UUID in newroot/etc/fstab
  13. mkswap /dev/mapper/rootvg-swaplv
  14. edit fstab
  15. edit newboot/boot/grub.conf
  16. mount –bind newboot/ newroot/boot
  17. mount –bind /dev/ newroot/dev
  18. mount -t proc none newroot/proc
  19. mount -t sysfs none newroot/sys
  20. chroot newroot
  21. echo -e “rootnoverify (hd1,0)\nsetup (hd1)” | grub –batch
  22. sync && poweroff

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