how to send last file with mailx

I use mailx to send some log files. The log files are generated hourly. So many files stored in that folder.

The log file is saved to a directory as "FILE_NAME=$ORACLE_SID`date + %m%d%y_%T`.

I use syntax like this:

mailx -s 'subject' myemail@company.com < /directory/$FILE_NAME

Because many files stored in that folder, but I only want to send the latest file with mailx command. Is my current code work? Please advise and give me some comments. Thanks.

If you're running mailx from the same script that you are generating the logfile in, then your syntax will work, as long as $FILENAME is set before you run the mailx command.

That would be the proper way to do it.

If you're running mailx separately, you'll have to figure out a way to find the last file, and not just keep sending the same file over and over, depending on how often the files are generated, and how often the mailx command is run.

malcolmpdx:

Thanks so much for your response. I haven't received any log file yet.

I have another question. Because I used cron job to trigger the shell script to generate the log files. In the end of cron job, I used to > /dev/null 2>&1 to disable cron job to send email. If I don't take this code off, will the mailx command in shell script continue to send log file to my email box?