Sponsored Content
Top Forums Shell Programming and Scripting Help needed with File Watcher script Post 302542836 by stunnerz_84 on Thursday 28th of July 2011 06:28:50 PM
Old 07-28-2011
Help needed with File Watcher script

Hi all,
I am writing a script to do the following:
1) Check if there are any new <csv> files (in abc directory) to process
2) If there is new file, then perform some operation on that file.
3) Move it to a different location(after step2 is successful)
4) Do further processing on the file

Problem is that there can be either one or more <csv> files that will be available in this directory.
All the above steps need to be performed on each new file.

Not sure how i could do this on multiple files

This is how i wrote the script...The script is not coming out of the loop when running this...

Code:
while true
do
  for file in *.csv;
    do
     #Some operation 
   mv $file /xxx/yyy
   #some operation
   done
  sleep 10
  done

PLEASE HELP!!!!!
Thanks in Advance!!!

---------- Post updated at 05:28 PM ---------- Previous update was at 05:12 PM ----------

Hi Guys..I found this in the forum which i think is similar to what im trying to do...but Im not sure how i need to make the script exit when there are no files in that directory to process...Is there a way to do that?? PLEASE let me know!!!

https://www.unix.com/shell-programmin...cher-help.html

Code:
while true
do
    file_list=$( ls file1_* 2>/dev/null )
    if [ -n "$file_list" ] ; then
        for file_name in $file_list ; do
            echo "Processing $file_name"
            #run some command...
            if [ $? -eq 0 ] ; then
                mv $file_name .done/ # Assume .done dir
            else
                mv $file_name .error/ # Assume .error dir
            fi
        done
    fi
    sleep 2
done


THANKS in advance!!!!

Last edited by pludi; 07-29-2011 at 03:12 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

file watcher job

Hello, I am trying to create a file watcher script to check for a file until certain time and throw a message. can some one please help me if there is script handy ?? Thanks, Sateesh (1 Reply)
Discussion started by: kotasateesh
1 Replies

2. Shell Programming and Scripting

File Watcher

Hi Please help me in this I want to execute a shell script abc.ksh. But I only want it to execute if file XYZ is not present. If file XYZ is present than I want to unix to sleep for 5 Sec and than agaian check for XYX existence. if it sleeps for more than 30 seconds ( 6 time )I want it to... (3 Replies)
Discussion started by: er_zeeshan05
3 Replies

3. Shell Programming and Scripting

File Watcher using autosys

Hi, Would like to kick off a script based on the file arrival using autosys but this has to monitor every second instead of a minute. Is there a better way to implement the monitor apart from cronjob and only need to use autosys in UNIX. Regards, Rajasilpa (0 Replies)
Discussion started by: rajasilpa
0 Replies

4. UNIX for Advanced & Expert Users

Need Script for File Watcher

Hi, I need a script for "FILE WATCHER" I have in a remote FTP location server named MAIN _104 EveryDay mrng 8 i hav to search couple of folders(COL, ATT, TRA) in that FTP server (MAIN_104), and if any files are present in that folders i hav to bring back to my computer and store it anywhere... (4 Replies)
Discussion started by: nani1984
4 Replies

5. Shell Programming and Scripting

File Watcher Help !!

Hi Experts I will have be having 3 types of files in directory file1_p0_date file1_p1_date file1_p2_date As soon as it sees any of the files it needs to kick off another process and also would need the file name For this I am creating a file watcher script which will look for file1* My... (2 Replies)
Discussion started by: westernmichnov
2 Replies

6. UNIX for Dummies Questions & Answers

Watcher Script

Hi Guys, I hope anyone can help me on how to create a watcher-script. The script will act as watcher wherein whenever it will find an error (say the word Error) in a file, it will prompt the user. Please help! br, rymnd_12345 (3 Replies)
Discussion started by: rymnd_12345
3 Replies

7. Shell Programming and Scripting

Looking out for the file-watcher

Hi friends, I do not have much thoughts so need any help on the below issue: I need to create shell script that will find the files & throw an error through job (autosys) when file not found. Daily we use to receive 3 files from a system. Obstacles: 1) All 3 files names are same. 2)... (4 Replies)
Discussion started by: tush
4 Replies

8. Shell Programming and Scripting

File watcher script

if test -n "$(find/data/path/ 'filename.txst' -print-quit) then echo "file found" exit 0 else echo "file not found" exit 46 fi So I basically looking to understand the if test -n "$(find/data/path/ 'filename.txst' -print-quit) line. Pls help to elaborate what this command... (6 Replies)
Discussion started by: Nsharma3006
6 Replies

9. Shell Programming and Scripting

Required help on a Generic File-watcher script

Hi All, Good morning... I have prepared a shell script which will monitor files in a certain folder and if available, SCP it to a destination path. Now the challenge I'm facing is my script is currently SCP-ing to only a single destination path. Wherever different destination path is in... (1 Reply)
Discussion started by: saps19
1 Replies

10. Shell Programming and Scripting

Help needed for Sleep (File watcher)

Hi All, I have a requirement, where I need to check for file. If file is not available then wait for 5 minutes and if it still not available, fail the process. It should check every one minute. If File available in between, should start remaining process. Now my problem is, I have both part... (0 Replies)
Discussion started by: ace_friends22
0 Replies
realpath(3C)						   Standard C Library Functions 					      realpath(3C)

NAME
realpath - resolve pathname SYNOPSIS
#include <stdlib.h> char *realpath(const char *restrict file_name, char *restrict resolved_name); DESCRIPTION
The realpath() function derives, from the pathname pointed to by file_name, an absolute pathname that names the same file, whose resolution does not involve ".", "..", or symbolic links. The generated pathname is stored as a null-terminated string, up to a maximum of {PATH_MAX} bytes (defined in limits.h(3HEAD)), in the buffer pointed to by resolved_name. RETURN VALUES
On successful completion, realpath() returns a pointer to the resolved name. Otherwise, realpath() returns a null pointer and sets errno to indicate the error, and the contents of the buffer pointed to by resolved_name are left in an indeterminate state. ERRORS
The realpath() function will fail if: EACCES Read or search permission was denied for a component of file_name. EINVAL Either the file_name or resolved_name argument is a null pointer. EIO An error occurred while reading from the file system. ELOOP Too many symbolic links were encountered in resolving file_name. ELOOP A loop exists in symbolic links encountered during resolution of the file_name argument. ENAMETOOLONG The file_name argument is longer than {PATH_MAX} or a pathname component is longer than {NAME_MAX}. ENOENT A component of file_name does not name an existing file or file_name points to an empty string. ENOTDIR A component of the path prefix is not a directory. The realpath() function may fail if: ENAMETOOLONG Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}. ENOMEM Insufficient storage space is available. USAGE
The realpath() function operates on null-terminated strings. Execute permission is required for all the directories in the given and the resolved path. The realpath() function might fail to return to the current directory if an error occurs. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
getcwd(3C), limits.h(3HEAD), sysconf(3C), attributes(5), standards(5) SunOS 5.10 9 Oct 2003 realpath(3C)
All times are GMT -4. The time now is 11:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy