This is a good first cut, but there are a couple of problems here:
If there are enough files in the directory, the expansion of * may overflow ARG_MAX limits on your system.
The list returned by find will not be sorted by timestamp, so there is no guarantee that the last file processed by this script will be the newest file. If it isn't, the next time you run the script some files will be processed again.
I think the following script will get around those problems:
But, if someone edits the last file processed in this directory after more files are added, this script (and the original script) will ignore the new files added after the last time the script ran until the time the file was edited. If that is a concern, the following may be a safer approach:
It keeps a list of files processed and skips any file in that list when the script is run again later. It doesn't care about timestamps other than the fact that it will hand ETL_PROCESS.sh unprocessed files in order from the oldest to the newest.
Note, however, that this script can fail if a filename in the directory containing files to be processed can contain a file name that is a substring of another file's name. You haven't given us any indication of how files are named, so if this is a concern the grep command in the pipeline in this script would have to be adjusted to account for the actual filenames you'll be using. And, of course, the list of processed files should be edited to remove old files when they are removed from the directory.
Assuming that ETL_PROCESS.sh provides some indication that it successfully processed a file, all of these scripts should verify that a file was processed successfully before continuing with later files. The first two scripts should exit and not process any newer files until the problem is fixed or some files may never be processed. The last script above only needs to avoid adding the failed file to the list of processed files (unless ETL_PROCESS.sh has to process input files in the order in which they were received).
Both of these scripts were written and tested using ksh, but there is nothing here that is ksh specific as long as you're using a shell that recognizes basic POSIX shell syntax requirements (such as bash and ksh).
Don C. provided, IMO, the best answer. Requires no extra files. Also works when the read program has issues and fails. It keeps the filenames unchanged. The files are not deleted after 15 days. You have to script that as well
I assume you use ksh -> #!/bin/ksh uses ksh as the shell
This script should be run once a week or maybe every day, as you decide. Do not change the 16 to a 15 or you will have problems - i'm not going into why fully but days are not dates they are the number of (86400 seconds) in the past. Not calendar days. I assume you want an email and have email on your UNIX box
Last edited by Neo; 03-19-2014 at 08:08 AM..
Reason: change name.
The problem is this one. I tar and gzip files on remote server
find . -ctime -1 | tar -cvf transfer_dmz_start_daily.tar *${Today}*.*;
Command
find . -ctime -1
Doesn't find files without extension
.csv .txt
I have to collect all files for current day, when the program... (1 Reply)
I need to find a word '% Retail by State' in the folder /usr/sas/reports/RetailSalesTaxallocation.
When I tried like below,
-bash-4.1$ cd /usr/sas/reports/RetailSalesTaxallocation
-bash-4.1$ find ./ -name % Retail by State
find: paths must precede expression: Retail
Usage: find ... (10 Replies)
Hello all,
this is my first and probably not my last question around here. I do hope you can help or at least point me in the right direction.
My question is as follows, I need to find files and possible folders which are not owner = AAA group = BBB with a said location and all sub folders ... (7 Replies)
Does anyone have any idea how to see only unread (new) e-mails in the Alpine client when using IMAP?
I finally have a fast IMAP client, but don't want to go over all the e-mails I've already read through other clients...
Thanks in advance for any hints.
---------- Post updated at 01:21 PM... (0 Replies)
Hi,
I have been having problem with pine for the past few weeks. I use email clinet Thunderbird to view my emails. Every time I open the thunderbird, all my emails were marked as unread. So, I logged into our email server to see what's wrong. even when I opened pine, all messages are labeled as... (0 Replies)
Hi all,
I use Conky monitor (Conky - Home) for my laptop and I needed a script to see the count of new messages on gmail/IMAP, then I made this small perl script
(I hope they can be useful to someone :))
gimap.pl
#!/usr/bin/perl
# gimap.pl by gxmsgx
# description: get the count of unread... (0 Replies)
Yes , I have to find a file in unix without using any find or where commands.Any pointers for the same would be very helpful as i am beginner in shell scritping and need a solution for the same.
Thanks in advance.
Regards
Jatin Jain (10 Replies)
I need to find files that have the ending of .out and that are older than 20 days. However, I cannot use find as I do not want to search in the directories that are underneath the directory that I am searching in.
How can this be done?? Find returns files that I do not want. (2 Replies)