Skip to content

Instantly share code, notes, and snippets.

Created October 5, 2010 12:37
Show Gist options
  • Save anonymous/611479 to your computer and use it in GitHub Desktop.
Save anonymous/611479 to your computer and use it in GitHub Desktop.
#!/bin/bash
#The target directory where you want the files to be saved.
#With trailing slash.
target="/home/harishankaran/"
cd "/tmp"
for i in `ls -1 Flash*`
do
#If the file is already copied, let's not copy again.
prev_size=0;
cur_size=0;
if [ ! -f "$target$i" ]
then
while [ 1 -eq 1 ]
do
prev_size=`du -s /tmp/$i | cut -f 1`
sleep 3;
cur_size=`du -s /tmp/$i | cut -f 1`
#Let's copy the file only after it has buffered completely.
if [ $cur_size -eq $prev_size ]
then
cp -f "/tmp/$i" $target
break
else
sleep 5
fi
done
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment