Basically I am looking to search for a certain string within a log file. If this string is present then I want to send an output file with the results of this string in it to me by email. If the output file has 0 as it's result the we email a successful backup. Script is below.
1) What do you mean by "$OUTPUT_FILE -gt 0" ?
In this way, you are just comparing the value of the variable ( i.e the path of the filename) with zero. which is wrong.
I guess, you want to compare the size of the file.
2) ">>" means you are appending to the file instead creating new file. if there is already existing file with that name, your count may go wrong.
3) [ ] itself used as a test operator. so no need of explicitly use of mentioning test keyword.
That script is now almost doing what I need. Sorry - I should have explained it better. If the value in the output file is 0 then the backup will have been successful as there are no errors. Any value greater than that signifies an error has occured and I need to investigate.
I have recieved a mail which had a value of 0 in it and "Backup Failed" as the subject.
Basically what is to test the value in the output file and if it is equal to 0 then the backup was successful. Anything more than 0 and the backup failed.
grep -i error $LOG_FILE| wc -l > $OUTPUT_FILE
-bash-3.00$ cat $OUTPUT_FILE
0
Subject: BACKUP FAILED ----> This needs to be a successful backup
as there are no errors. Anything
greater than 0 is a backup failure.