I am new to scripting.I am trying to mail the recent file contents but not the below script which i wrote is not working.Please guide me in finishing the script
In addition to what Scrutinizer has already said, the command:
File=$(find /Directory path/*.fnr | tail -1)
is very strange. Unless the pathname matching pattern path/*.fnr fails to match any pathnames, the search of the file hierarchy rooted in /Directory doesn't do anything but slow down finding the last file in the file hierarchies rooted in the pathnames matched by path/*.fnr . Note also that unless the pathnames matched by path/*.fnr are non-directory files, the last pathname printed by find from this command will be random (i.e., not necessarily in alphanumeric order, not time created order; just random). What is the intent in picking a random file from the output of find ?
And, once you have selected a file, copying the contents of file into a variable with the sole purpose of copying the text into a mail message wastes memory, time, CPU bandwidth, and I/O bandwidth. It would be MUCH more efficient to replace:
content=$(cat "$File")
echo "$content" | mail -s "Subject " "myname@company.com"
If you can't find out yourself what the error msg means, and if you want meaningful help, wouldn't it be wise to answer questions needed to track down the details of your problem?
As I said before, using cat to send the contents of your chosen file to the mail utility is grossly inefficient and in this case is generating an error that could have been easily avoided if you had followed my suggestion in post #3 in this thread.
In addition to that there is nothing in your find command that has anything to do with finding a file with today's date.
If you would give us clear details about the names and locations of the files from which you want to select today's file(s), how you determine that a file is today's file (Is it part of the name of the file? Is it the last modification timestamp of the file? Is it the last access timestamp of the file? ...), we might be able to make some meaningful suggestions. If you keep us in the dark, all we can do is treat the symptoms indicated by the error messages you are describing to us. Fixing those symptoms might or might not lead you to something that will do what you are trying to do.