We have a script that runs and generates multiple files, but not every file will have content. The script writes any output to a single file, but we break out the results to other files. Files contain ping results (slow, not reachable, not accessible), so there are some instances where we can reach all so the other two files will initially be created, but by the end of the script may not have anything in them. We have lines that remove the files, but after the mail is sent, so we have files attached that are there, but empty.
Is there a way outside of writing a multi-if conditional statement that will ONLY attach files that have lines or content?
This is my line for mailx to send the email with attachments:
(cat $FINAL) | mailx -s "Application ${VER} BashScript processing results"
-a $LOGFILE -a $INACHOSTLIST -a $FAILHOSTLIST -a $SLOWHOSTLIST
If any of these $INACHOSTLIST, $FAILHOSTLIST or $SLOWHOSTLIST are empty, I would prefer not to attach them. May seem trivial to leave them attached with nothing in them, but trying to clean up the process. Does this require that each possible combination be validated through an if statement?