Source Destination State Lag Status
CQA02W2K12pl:D:\CAQA infrabkpsrvpl:/vol/CQA02W2K12srv/CAQA Snapvaulted 13:46:44 Idle
DBIntranetpl:E:\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL infrabkpsrvpl:/vol/DBIntranetsrv/MSSQL10 Snapvaulted 13:46:43 Idle
And the file has hundreds of such entries.
What I'm interested in is the lag column- which is always in the format hh:mm:ss. I want to read the file line by line, check if the "lag" column in greater than 48:00:00 (just matching the hour field would be enough) and if the lag is greater than 48:00:00, append that particular line to another file.
How can I achieve this?
I tried awk, but since some of the line descriptions have spaces, $4 is not always lag column.
Actually, I did, however, since the OP came back with another criteria that superseded the original first post and since there was not clear indication on your part, I tested based on the final request which I just had posted.
Another consideration is that the test can not be reversed without unintended consequences.
Hi Aia,
You saw new requirements; I saw non-working code. We'll have to let the OP clarify the intent.
My code was written to meet the stated requirements. If the requirement is less than 48 hours instead of greater than (or greater than or equal to) 48 hours, that would be:
/usr/kerberos/bin/rsh infrabkpsrvplp snapvault status | awk '$(NF-1) ~ /..:..:../ {split($(NF-1), a, ":");if(a[1] > 48){printf("\n");printf("Backup Source: ");print$1;printf("Destination Filer: infrabkpsrvplp\n");printf ("Time Since Last Backup: ");print$(NF-1)}}' >> /var/adm/snapvault/body
Instead of dumping the output on a file and then awk'ing the file, I sent the output to a "body" file then I would just mail myself the content of body. Which I recieve as below:
Backup Source: m1storagepp:D:\EM1\EM1-Applications\MATRIX-Applications-LG\Design
Destination Filer: infrabkpsrvplp
Time Since Last Backup: 172:55:03
Backup Source: m1storagepp:D:\EM1\EM1-Applications\MATRIX-Applications-PortfolioManagement\Dev\InhouseTools
Destination Filer: infrabkpsrvplp
Time Since Last Backup: 220:55:04
Thanks again for your support and apologies for not responding earlier- Onsite visits
-Pocodot.
---------- Post updated at 05:58 PM ---------- Previous update was at 05:57 PM ----------
Also, I'm happy to answer any questions you may have.