Conditional File Movement script scheduled using CRON job

Hi All,
i am trying to automate a process and have to create a unix script like wise. I have a scenario in which i need to automate a file movement. Below are the steps i need to automate.

  1. Check whether a file (Not Fixed name-Pattern search of file say 'E*.dat') is present in a directory /hm/srcfiles. In this directory, there will be files placed by a JSP on adhoc basis like E1.dat,E2.dat,E3.dat ......
  2. A script/Job keeps sniffing this directory for files of this kind.... the moment it finds one, it should transfer the file to other directory say /hm/tgt but with renaming it to 'FILE.dat'. This transfer is conditional, the file movement should happen only if the /hm/tgt directory does not contain 'FILE.dat', and if 'FILE.dat' is present, it should wait and try to move the file again untill succeded.
    3.The cleanup of file 'FILE.dat' from /hm/tgt/FILE.dat happens by another shell script called by a different application. I am kind of able to write that (I have not worked with unix scripting much :o )
    4.I guess CRON job scheduling should be used for triggering the file movement script, correct me if i am wrong.
    5.This CRON job should run contineously and trigger the script when ever the
    file named like 'E*.dat' arrives. Also if many files are present in /hm/src directory, all the files should be processed sequentially :slight_smile:

Thanks for the patience to read the explaination. I do not know scripting much OR have used CRON job scheduling before. Can someone help me in this regard. I a sound too naive with UNIX, it is because i am :o

Hi,

First, create a shell named "toto.sh" and doing following commands :
if [ -f /hm/srcfiles/E*.dat ]
then
mv /hm/srcfiles/E*.dat /hm/tgt
...
fi

Second, edit cron daemon
crontab -e

Third, in crontab put "toto.sh" with this parameters for exemple :

  • 7-22 * * 1-5 <PATH>/toto.sh 1>/dev/null 2>&1
    (execution between 7am and 10pm, from monday to friday)

Rgds.

WHAT THE PREVIOUS IS CORRECT BUT INSTEAD OF SPECIFIYNG IN THE CRONTAB - e go for /etc/crontab and specify there