The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Auto copy for files from folder to folder upon instant writing Bashar UNIX for Advanced & Expert Users 2 08-21-2008 11:44 AM
Commercial KVM-based virtual desktop program arrives iBot UNIX and Linux RSS News 0 04-29-2008 09:50 PM
Ksh Storing Multiple Files and reading each line in each file. developncode UNIX for Dummies Questions & Answers 1 04-08-2008 01:44 PM
Parse the .txt file for folder name and FTP to the corrsponding folder. MeganP Shell Programming and Scripting 3 07-03-2007 10:54 AM
grep multiple text files in folder into 1 text file? coppertone UNIX for Dummies Questions & Answers 7 08-23-2002 11:50 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-25-2005
Registered User
 

Join Date: May 2005
Posts: 4
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
Reply With Quote
Forum Sponsor
  #2  
Old 05-25-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
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
Reply With Quote
  #3  
Old 05-26-2005
Just Ice's Avatar
Lights on, brain off.
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 629
if time is critical ... use "sleep 1" instead to check every second ...
Reply With Quote
  #4  
Old 05-26-2005
Registered User
 

Join Date: May 2005
Location: Montreal
Posts: 17
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
Reply With Quote
  #5  
Old 05-26-2005
Registered User
 

Join Date: May 2005
Posts: 4
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
Reply With Quote
  #6  
Old 05-26-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
^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
Reply With Quote
  #7  
Old 05-26-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
I tried your code on my machine and it works perfect.

Vino
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0