Bash
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#!/bin/bash currentHosts="/etc/hosts" myHostsPart="/etc/hosts.my" newHosts="http://winhelp2002.mvps.org/hosts.txt" timeStamp=$(date '+%Y-%m-%d_%H-%M') log="/var/log/hosts-file-update" cp ${currentHosts} ${currentHosts}.${timeStamp}.bak wget ${newHosts} -O ${currentHosts}.${timeStamp} wgetstat=$? if [ ${wgetstat} -eq 0 ]; then cat ${myHostsPart} > ${currentHosts} cat ${currentHosts}.${timeStamp} >> ${currentHosts} echo "${timeStamp} ok" >> $log else rm -f ${currentHosts}.${timeStamp}.bak echo "${timeStamp} error, wget err code = ${wgetstat}" >> $log fi |
Powershell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$Log = "c:\Windows\System32\drivers\etc\hosts-update.log" $newHostsURL="http://winhelp2002.mvps.org/hosts.txt" $newHosts = "c:\Windows\System32\drivers\etc\HOSTS.new" $myHostsPart = "c:\Windows\System32\drivers\etc\HOSTS.my" $Hosts = "c:\Windows\System32\drivers\etc\HOSTS" $Timestamp = $([System.DateTime]::Now.ToString('yyyy-MM-dd--HH-mm')) Copy-Item "$Hosts" "$Hosts.$Timestamp.bak" $Client = New-Object System.Net.WebClient $Client.DownloadFile( $newHostsURL, "$newHosts.$Timestamp") $downStat = $? if ($downStat) { Get-Content $myHostsPart,"$newHosts.$Timestamp" | Out-File $Hosts -Encoding utf8 "$Timestamp ok" >> $Log } else { Remove-Item "$Hosts.$Timestamp.bak" -Force "$Timestamp error" >> $Log } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#!/bin/bash mypass='Password' # one password for each PFX file pfx=( 'domain1.pfx' 'domain2.pfx' 'domain3.pfx' ) for ((x = 0; x < ${#pfx[@]}; x++)) do echo "Exporting ${pfx[$x]}..." openssl pkcs12 -in ${pfx[$x]} -clcerts -nokeys -out ${pfx[$x]}.cer -passin pass:$mypass openssl pkcs12 -in ${pfx[$x]} -nocerts -nodes -out ${pfx[$x]}.enc.key -passin pass:$mypass openssl rsa -in ${pfx[$x]}.enc.key -out ${pfx[$x]}.key rm -f ${pfx[$x]}.enc.key echo "Done!" done |
Sometimes it suits me…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
param ( [Parameter(Mandatory=$true)][string]$target, [Parameter(Mandatory=$false)][int]$waitUntilNextCycle=1, [Parameter(Mandatory=$false)][bool]$displayOkStatus=$true ) $ping = New-Object System.Net.NetworkInformation.Ping function Get-Timestamp { return [System.DateTime]::Now.ToString('HH:mm:ss') } if (!$displayOkStatus) { Write-Warning "Only connection errors will be displayed!" } while ($true) { try { $res = $ping.send($target) $status = $res.Status if ($status -ilike "Success") { if ($displayOkStatus) { Write-Host "[Ok $(Get-Timestamp)]" -NoNewline -BackgroundColor DarkGreen -ForegroundColor White } } else { Write-Host "[$status $(Get-Timestamp)]" -NoNewline -BackgroundColor DarkRed -ForegroundColor White } Start-Sleep -Seconds $waitUntilNextCycle } catch { Write-Host "[DNS or network connection error $(Get-Timestamp)]" -NoNewline -BackgroundColor Black -ForegroundColor White } } |