locked
Script question RRS feed

  • Question

  • Hello

    I have a simple script to monitor a serverlog and with this script,  the pc speaks the complete useragent string.

    I want it  to filter  out just the name after "compatible"  and speak only that word,

    Is that possible?

    Thank you

    Get-Content useragent.log -Tail 1 -wait | % {if ($_ -match "Compatible")
    {Add-Type -AssemblyName System.speech
    $Location = "$env:useragent.log"
    $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
    $Contents = Get-Content $Location -Tail 1 | where {$_ -match "Compatible"}
    $speak.Speak($Contents)}}

    • Moved by Bill_Stewart Friday, March 15, 2019 6:04 PM This is not "train me in basics step-by-step in a forum" forum
    Monday, January 14, 2019 10:19 AM

All replies

  • It is totally depend on the structure of string that consist with Compatible. Can you please post or copy few lines from the log file that contains word "Compatible"
    Monday, January 14, 2019 11:47 AM
  • 'some other stuff compatible zippy doodah' -match 'compatible\s(.*)\s'
    $matches[1]
    


    \_(ツ)_/

    Monday, January 14, 2019 1:46 PM
  • Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)

    The Speech.Synthesis read the whole line.

    Monday, January 14, 2019 1:54 PM
  • Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)

    The Speech.Synthesis read the whole line.

    $speak.Speak($Contents)}}

    Don't be a Googlebot.  Googlebots are mindless. 


    \_(ツ)_/

    Monday, January 14, 2019 1:58 PM
  • I have another question.

    This script is used to monitor logfile or textfile it searches the last line in the file "live"  and send the word 200 to the speech.

    Get-Content C:logfile.log -Tail 1 -wait | % {if ($_ -match "200") {Add-Type -AssemblyName System.speech
    $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
    $speak.Speak('200')}}

    If i want to monitor another file, then i must start a new powershell session, and so on. This takes much memory from the PC.

    How can i combine these three examples in one powershell script?

    example:

    Get-Content C:logfile.log -Tail 1 -wait | % {if ($_ -match "200") {Add-Type -AssemblyName System.speech
    $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
    $speak.Speak('200')}}

    Get-Content C:logfile.log -Tail 1 -wait | % {if ($_ -match "300") {Add-Type -AssemblyName System.speech
    $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
    $speak.Speak('300')}}

    Get-Content C:logfile.log -Tail 1 -wait | % {if ($_ -match "400") {Add-Type -AssemblyName System.speech
    $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
    $speak.Speak('400')}}

    Tuesday, January 15, 2019 8:31 AM
  • This does not use enough memory to be worth paying attention to.

    If you use jobs or workspaces there would still be much the same memory usage.


    \_(ツ)_/

    Tuesday, January 15, 2019 2:46 PM
  • I found this script that works, but it shows the whole line in the output file

    I just want it to output the word that is in the filter.....  "anyword"  will just show in the output file

    How do i do it?

    $inputFile = "logfile.log"
    $outputFile = "logfile2.log"
    $filters = "anyword"
    Get-Content $inputFile -Tail 1 -wait | Select-String -pattern $filters -notmatch  | Out-File $outputFile

    Thursday, January 17, 2019 2:40 PM