reading a file name as soon as that files arrives into a folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reading a file name as soon as that files arrives into a folder
# 1  
Old 05-25-2005
reading a file name as soon as that files arrives into a folder

Hi,

Thanks in Advance..

i have the following requirement, some one please help me..

An unix shell script has to pick up the file name from a folder as soon as that file comes into that folder.

Regards,
Alo
# 2  
Old 05-25-2005
How about using a sleep ?

Code:
#! /bin/sh

while true
do
[ -f /path/to/the/new/file ] && echo "/path/to/the/new/file"
#sleep for 1 min
sleep 60
done

Vino
# 3  
Old 05-26-2005
if time is critical ... use "sleep 1" instead to check every second ...
# 4  
Old 05-26-2005
If you can have the check done every minute, the most efficient way is probably to schedule it via the crontab utility. Here's what your cron entry could look like:

* * * * * move_file.sh /the_dir/the_file

This entry would run a script (move_file.sh) every minute of every day. The script just needs to test the exeistence of the file and do whatever needs to be done with it.

HTH

Réal
# 5  
Old 05-26-2005
Vino,

Thanks for your post.

i m using ksh shell script and tested the following file,

#! /bin/ksh

while true
do
[ -f /synchen/dtazv/fhu/sourcedir ] && echo "/synchen/dtazv/fhu/sourcedir"
#sleep for 1 min
sleep 60
done



the following error has been thrown,
$ ksh Test2.sh
Test2.sh[2]: ^M: not found.
Test2.sh[3]: 0403-057 Syntax error at line 8 : `done' is not expected.

Please give your advice on this.

Regards,
Alo
# 6  
Old 05-26-2005
^M character shows you transfered the script from a windows m/c to unix.

Do this..

Code:
dos2unix Test2.sh

And try to run it now...

If it doesnt work try this

Code:
#! /bin/ksh

while true ;
do
[ -f /synchen/dtazv/fhu/sourcedir ] && echo "/synchen/dtazv/fhu/sourcedir"
#sleep for 1 min
sleep 60
done

Vino
# 7  
Old 05-26-2005
I tried your code on my machine and it works perfect.

Vino
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

2. Shell Programming and Scripting

Shell scripting for moving folder specific files into target directory of that country folder.

I need help to write shell script to copy files from one server to another server. Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Discussion started by: naresh2389
3 Replies

3. Shell Programming and Scripting

Compare files in a folder based on another file

I have a file named file.txt that looks as follows //class1.txt 45 234 67 89 90 //class2.txt 456 34 78 89 120 class1 and class2.txt are the names of files in a folder named folder1. The content of class1.txt file in folder1 67 9 89 5 234 9The content of class2.txt file in... (1 Reply)
Discussion started by: jaff rufus
1 Replies

4. UNIX for Dummies Questions & Answers

To delete the oldest files in a file when file count in the folder exceeds 7

Hi All, I need to delete the oldest file in folder when the file count in the folder exceed 6 ( i have a process that puts the source files into this folder ) E.x : Folder : /data/opt/backup 01/01/2012 a.txt 01/02/2012 b.txt ... (1 Reply)
Discussion started by: akshay01987
1 Replies

5. Shell Programming and Scripting

Reading files under a folder and formatting content of each file

I have 'n' number of files in a folder .each file in the folder "myfolder" is having the content like. COLNAME ------------ AAAAAA BBBBBB CCCCCC DDDDDD ... ... ... ZZZZZZ 26 recrod(s) selected. My request is by reading each file in "myfolder" and format each file such a way... (18 Replies)
Discussion started by: rocking77
18 Replies

6. Shell Programming and Scripting

Script check for file, alert if not there, and continue checking until file arrives

All, Is there a way to keep checking for a file over and over again in the same script for an interval of time? Ie If { mail -user continue checking until file arrives file arrives tasks exit I don't want the script to run each time and email the user each time a file... (4 Replies)
Discussion started by: markdjones82
4 Replies

7. Shell Programming and Scripting

Find all text files in folder and then copy to a new folder

Hi all, *I use Uwin and Cygwin emulator. I´m trying to search for all text files in the current folder (C/Files) and its sub folders using find -depth -name "*.txt" The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Discussion started by: cgkmal
4 Replies

8. Shell Programming and Scripting

check how many files in folder or total files in folder

Hi all, I have copied all my files to one folder.and i want to check how many files (count) in the folder recently moved or total files in my folder? please send me the query asap. (3 Replies)
Discussion started by: durgaprasad
3 Replies

9. Shell Programming and Scripting

script for Finding files in a folder and copying to another folder

Hi all, I have a folder '/samplefolder' in which i have some files like data0.txt, data1.txt and data2.txt. I have to search the folder for existence of the file data0.txt first and if found have to copy it to some other file; next i have to search the folder for existence of file... (5 Replies)
Discussion started by: satish2712
5 Replies

10. UNIX for Advanced & Expert Users

Auto copy for files from folder to folder upon instant writing

Hello all, I'm trying to accomplish that if a file gets written to folder /path/to/a/ it gets automatically copied into /path/to/b/ the moment its get written. I thought of writing a shell script and cron it that every X amount of minutes it copies these files over but this will not help me... (2 Replies)
Discussion started by: Bashar
2 Replies
Login or Register to Ask a Question