script to check files,change the file permissions and move it to folder

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

script to check files,change the file permissions and move it to folder

etlvij
Hi All, Need help on the below requirement: we are using to move files for archive process.The script list the files, change the permission on the file and moving it to a different folder. Sometimes the script is moving the file before the contents fully generated. We need to add a delay after getting the list before starting the loop. Is this possible? we don’t want to add delay in the loop as it will slow down the process. Ex:The requirement is We need to get the list of files that are fully transferred to the location and then we need to change permissions and move those files to the target directory. lets say we have a file 'X' which is completely transferred and creation time is 2:30PM and we have another file 'Y' for which the contents are still loading to the file then creation time will be "2:35PM". So, in this case, we have to take only the 1st file i.e., 'X' and change the permissions and move it to archive folder. ### Script to change the file permissions and move it to folder # function starts here function call_mv_files { cd $IN_DIR if [ "$?" = "0" ]; then for i in $(/usr/bin/ls *) do echo "ext: changing file permission $i" /usr/bin/chmod 775 $i echo "ext: Moving $i" /usr/bin/mv $i $OUT_DIR/$i done else echo "Error accessing folder " $IN_DIR fi } ### program starts here ################# IN_DIR=/export/home/in OUT_DIR=/export/home/out call_move_files Thanks in advance, regards, etlvij