Răzvan Cosma's scratchpad

random scripts of random value

Assumes ‘sudo’ is required. Net::OpenSSH::Parallel installed using cpanspec on CentOS 7

continue reading…

my .bash_profile

Comments off
shopt -s checkwinsize
shopt -s histappend
shopt -s cmdhist
PROMPT_COMMAND='history -a'
alias mc='caffeinate -i mc -d'
export CLICOLOR=1
export EDITOR='/usr/local/bin/joe'
complete -C aws_completer aws
eval "$(~/repos/rakudobrew/bin/rakudobrew init -)"
eval "$(rbenv init -)"

Expects some env vars defined in the GoCD environment or pipeline definition: Jenkins HTTP address, login, name of job to build, polls for a successful exit code then downloads the artifacts zip.

continue reading…

perl -MExtUtils::Installed -e "use v5.10; $i=ExtUtils::Installed->new(); @m=$i->modules(); foreach $mm (@m) {say $mm .' - '. $i->version($mm);}"

find maxdepth


$ perl -e 'use File::Find; find (sub { $d=$File::Find::dir=~tr[/][]; return if $d>6; if (-f and /config.xml/) {open $f,"<",$_; @a=<$f>; close $f; @m = grep /some string/i @a; print "\nfound in ",$File::Find::name,"\n",@m if @m} },"/opt/hudson/work/jobs")'

Fixing Zabbix on a bunch of Windows machines with local accounts

for /F "tokens=1-3 delims=," %%A in (zz.list) do (
 echo %%A %%B %%C
 net use "\\%%A.mydomain.com\C$" %%C /user:%%A\%%B
 xcopy /q /y zabbix_agentd.win.conf "\\%%A.mydomain.com\C$\Program Files (x86)\Zabbix Agent\zabbix_agentd.conf"
 net use "\\%%A.mydomain.com\C$" /delete
 net use "\\%%A.mydomain.com\IPC$" %%C /user:%%A\%%B
 sc \\%%A.mydomain.com stop "Zabbix Agent"
 sc \\%%A.mydomain.com start "Zabbix Agent"
 net use "\\%%A.mydomain.com\IPC$" /delete

and HostnameItem=system.hostname[host] in conf

thrttl unix - - n - - smtp -o syslog_name=smtp-throttled
thrttl_destination_rate_delay = 10s
thrttl_destination_concurrency_limit = 1
thrttl_destination_recipient_limit = 2
transport_maps = regexp:/etc/postfix/transport
/\@mydomain\.com$/ thrttl:

Set up WSUS to automatically approve security patches (because it’s the right thing to do),

$wsus = Get-WSUSServer
$class = $wsus.GetUpdateClassifications() | ? {$_.Title -In ('Critical Updates','Security Updates')}
$rule = $wsus.GetInstallApprovalRules() | Where {$_.Name -eq "Default Automatic Approval Rule"}
$class_coll = New-Object Microsoft.UpdateServices.Administration.UpdateClassificationCollection
$class_coll.AddRange($class); $rule.SetUpdateClassifications($class_coll); $rule.Enabled = $True; $rule.Save()
$config = $wsus.GetConfiguration(); $config.TargetingMode = "Client"; $config.Save()

continue reading…

$ping = New-Object System.Net.NetworkInformation.Ping
Get-Content .\list.txt | ForEach-Object { "{0,-15} {1,16}" -f $_,$($($ping.Send($_).Address).IPAddressToString 2>$null) }


%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

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