Hello there,
I'm using a read-while loop to preserve the word Failed within a text file. For example, if the word Failed exist twice in a single text file, my STDOUT should re-direct to a new text file and display Failed twice.
My output is attached to this thread. I would like output to display only 5 lines not 20 lines. Based on my script, my echo command is only calling variable one time, not four times, according to script output.
Below is my script:
#!/bin/bash
var="TestServer"
file="/usr/local/bin/Production/ESXiTestServer/cron.log"
go=$(grep 'Failed' "$file")
while read line; do
echo "from:me
subject:Failure on $var
message:${go}" >> mywindowsfile.txt
# Convert linux txt file to Windows txt format
awk 'sub("$", "\r")' mywindowsfile.txt > mywindows.txt
done < "$file"
I don't know exactly what is going on with output. Any suggestions on how to fix my output. My goal is to have output look like this:
from:TestServer@email.com
subject:Failure on TestServer
message: Physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SAS, 36 GB, Failed)
Physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SAS, 36 GB, Failed)
```[/b]