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 } |
Díky, tohle jsem neznal (hosts file) :)