Wait for text in log file (awk anyone?)
Hi there!
I want to write me a backup script. The overall procedure I have in mind is: - log in as root - start script - start backup disk (external 4 TB USB drive) - wait until backup finishes So what I see in /var/log/messages when the backup disk is plugged in is something like this: Code:
Sep 11 01:47:06 mimi kernel: [50974.093519] sd 7:0:0:0: [sdh] Spinning up disk... So is there anyone who can help me with this? Ideally the result would run on any Unix and would use old, reliable and widely available tools. TIA Gregor |
You could use awk, e.g.
Code:
tail -f /var/log/messages | awk '/.....ready/ { exit; }' |
Quote:
Just for the record - my very quick-and-dirty script: Code:
#!/bin/bash |
This does not do what you want:
Quote:
You could replace the regex with either "/ \.\.\.\.\.\.\.\.\.ready$/" or simply "/ \.{9}ready$/", but an even better option would be to do a plaintext match on the last field of the line ($NF) with exactly what it contains, i.e: Code:
tail -n 1 -f /var/log/messages | awk '$NF == ".........ready" { exit; }' |
Quote:
Gregor PS: Having implemented (well, copy+pasted) what you wrote I looked up 'NF' in the awk man page and I am irritated by '==' (are you comparing a number and a string?!) and decided I should take a closer look at awk. Once there was an O'Reilly book on awk an sed ... |
All times are GMT -5. The time now is 07:03 AM. |