Hello everyone, I'me new to shell scripting and have been trying to create a custom script to do the following steps -
- search for the word servicedown within all log files in a specific directory
- After finding the keyword servicedown, grab latest timestamp from that log
- Set variable with results from #2
- loop previous log files and grab the timestamp from the last line from next newest log in that directory.
- Set a variable with the results from #4
- Calculate difference between the 2 timestamps in minutes.
Here is what I have so far, and it's very incomplete. I've been trying to piece this script together as best as I can and could really use any help I can get.
#!/sw/bin/bash
LogFile="abc.server-ny-abc01.200908270000+0000.log"
LogFile2="$(ls -lt /abc01/ihost/log/abc*log|/sw/bin/grep -v abc.log|/sw/bin/grep -A 1 $LogFile| /sw/bin/tail -n 1| /sw/bin/sed -n "s/.*\(abc\..*\)/\1/p")"
/sw/bin/tail -n 1 /abc01/imail/log/$LogFile2 | /sw/bin/awk '{print "Crash Start",substr($0,1, 13)}'
/sw/bin/grep -i "servicedown" /abc01/ihostlog/abc.log | /sw/bin/awk '{print "Crash End",substr($0,1, 13)}'
exit 0
Here is the current format of the logfiles being generated.-
abc.server-ny-abc01.200908270000+0000.log