Ошибка: $ digest уже выполняется

  1. Вычислить хэш списка файлов
  2. Сохранить его в словаре
  3. Проверить каждый хэш на интервале
  4. Выполнить действие при хеше
  5. [hr>
    function watch($f, $command, $interval) {
        $sha1 = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
        $hashfunction = '[System.BitConverter]::ToString($sha1.ComputeHash([System.IO.File]::ReadAllBytes($file)))'
        $files = @{}
        foreach ($file in $f) {
            $hash = iex $hashfunction
            $files[$file.Name] = $hash
            echo "$hash`t$($file.FullName)"
        }
        while ($true) {
            sleep $interval
            foreach ($file in $f) {
                $hash = iex $hashfunction
                if ($files[$file.Name] -ne $hash) {
                    iex $command
                }
            }
        }
    }
    

    Пример использования:

    $c = 'send-mailmessage -to "admin@whatever.com" -from "watch@whatever.com" -subject "$($file.Name) has been altered!"'
    $f = ls C:\MyFolder\aFile.jpg
    
    watch $f $c 60
    
29
задан iJade 12 February 2013 в 17:29
поделиться