Korn shell script to sync/move files that are not in use


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Korn shell script to sync/move files that are not in use
# 1  
Korn shell script to sync/move files that are not in use

Hello all. This may seem like a dumb/easy question but right now I have a little script I made that uses rsync to sync a directory that has files in it that may or may not be complete files. I want to come up with a better solution for this. What it is is I have a directory lets say /incomplete that has files that could still be downloading or being transferred to that directory. I want to grab files in that /incomplete directory that are complete and move to another directory called /complete. Is there a good way of doing this so that I can only move completed files without corrupting or messing with the files that are not finished transferring to the /incomplete folder? Thanks in advance and I hope that I was clear.
# 2  
Hi linuxn00b,
Welcome to the forum.

You may want to use fuser or lsof
This User Gave Thanks to clx For This Post:
# 3  
@anchal_khare thanks for idea. I will mess around a bit and modify what I have in my script and see if I have anymore questions.

---------- Post updated at 06:17 PM ---------- Previous update was at 06:16 PM ----------

OK I thought I had a good idea of what to do but now I am a little confused. Can you possibly write up a short example of your idea into a little script? Sorry for the lack of knowledge. I can run lsof and see what is being used but then I am not sure what to do to then transfer the files that are not still open. Thanks

Last edited by linuxn00b; 10-10-2011 at 10:42 PM..
# 4  
Quote:
Originally Posted by linuxn00b
Hello all. This may seem like a dumb/easy question but right now I have a little script I made that uses rsync to sync a directory that has files in it that may or may not be complete files. I want to come up with a better solution for this. What it is is I have a directory lets say /incomplete that has files that could still be downloading or being transferred to that directory. I want to grab files in that /incomplete directory that are complete and move to another directory called /complete. Is there a good way of doing this so that I can only move completed files without corrupting or messing with the files that are not finished transferring to the /incomplete folder? Thanks in advance and I hope that I was clear.
This is more than just using rsync as a form of backup. What you really need is a list of files that are opened and then have rsync to exclude to backup those files. However, files could be opened and/or closed at the point when rsync has compiled a list of files to copy and started the backup process.

A better solution is to generate a list of open files and use snapshot to take a static copy of the entire file system. rsync the files from the static file system to the backup destination. At the end, ensure the opened files are closed and re-backup those files that are opened previously.
# 5  
still having problems

so I have a few ideas in place here from some stuff I have came across on this forum and online. But I am missing something in each of these scripts. Ideas welcome please. What am I missing here??? Smilie

Code:
#!/usr/bin/ksh

FILE_NAME=$i
FILE_OPEN=`lsof | grep $FILE_NAME`
ls -l /usr/local/bin/test | while read a b c d e f g h i; do
	if [ -z $FILE_OPEN ] ;then
		echo "File NOT open"
	else
		echo "File Open"
	fi
done

Code:
#!/usr/bin/ksh

file1=`cksum $i | awk '{print $1}'`
sleep 10
file2=`cksum $i | awk '{print $1}'`

ls -l /usr/local/bin/test | while read a b c d e f g h i ; do
	if [  $file1 = $file2 ] ; then
		echo "Both are same" $file1 $file2
	else
		echo "Both are different" $file1 $file2
	fi
done

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #77
Difficulty: Easy
MINIX was a Unix-like operating system created for educational purposes.
True or False?

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

Korn shell Script to combine Two files in one

Hello All , I am new to this Forum, I am trying to write a script to combine two data files with 1 column in common and others columns are different . File1 Apple 29 tomatao 4 grapes 25 File2 Apple fruit tomatao veg grapes fruit other (3 Replies)
Discussion started by: gagan0119
3 Replies

3. Shell Programming and Scripting

crontab using shell script to sync files.

Hi, I developed one shell script where it will sync the files using perforce, #!/bin/bash TERM=linux export TERM clear echo "" $PATH echo "" cd /u/userk/p4/p4_client/TES_DATE echo "" echo "Sync p4 " p4 sync echo "Executing for second time " p4 -u userk -p p4net:161 -c... (8 Replies)
Discussion started by: asak
8 Replies

4. Shell Programming and Scripting

Need shell script to move files

Hi , I need a simple shell script to move the files from one directory to another directory after every 1 hour..!!! ?? (1 Reply)
Discussion started by: SARAL SAXENA
1 Replies

5. Shell Programming and Scripting

korn shell remove files question

how do you show each filename in a giving directory and delete the specific file in korn script i was thinking using ls rm ? but i cant make it work (0 Replies)
Discussion started by: babuda0059
0 Replies

6. Shell Programming and Scripting

Shell script to move files to 3 different folders

Hi guys: I've got this problem, I want to move a bunch of files to 3 different folders, without any specific order, and I'm trying to automatize it with a shell script. I'm a newbie at shell scripting so this is my first try: #!/bin/bash COUNTER=`ls -1 | wc -l` while do ARRAY=(... (11 Replies)
Discussion started by: wretchedmike
11 Replies

7. Shell Programming and Scripting

Shell script to move certain files on scheduled time

Hi Friends, I want a shell script which will move certain .jar files from a specified location (say /publish/content) to (/publish/archive) on every saturday morning 6 am. One more thing to add is that before moving files it must check free space at (/publish/archive), if it is more than 60 %... (7 Replies)
Discussion started by: abhishek27
7 Replies

8. UNIX for Dummies Questions & Answers

Initializing files to empty in korn shell

hello, i want to know how to initialize a file to an empty one in korn shell scripting? i'm using a file name and building it during a while loop using >>. The problem occurs when the file is not empty before reaching the while loop. therefore, i want to initialize it before the loop to get... (6 Replies)
Discussion started by: alrinno
6 Replies

9. UNIX for Dummies Questions & Answers

Korn shell awk use for updating two files

Hi, I have two text files containing records in following format: file1 format is: name1 age1 nickname1 path1 name2 age2 nickname2 path2 file 1 example is: abcd 13 abcd.13 /home/temp/abcd.13 efgh 15 efgh.15 /home/temp/new/efgh.15 (4 Replies)
Discussion started by: alrinno
4 Replies

10. UNIX for Dummies Questions & Answers

Lookup between 2 files ( korn shell )

Hi All., i have a problem. I hope i can get some help on this issue here; i have 2 txt files say file1 and file 2 file1 has; WLMT:XXXXXXXX:cp DOLR:YYYYYYY:ascii,unblock WLG:TTTTTTT:dd:73:ascii,unblock MAR:SSSSSS:dd:152:ascii,unblock GGG:QQQQQQQQQQ:112:ascii,unblock EIE:CCCCCCCC:cp... (17 Replies)
Discussion started by: pavan_test
17 Replies

Featured Tech Videos