Discussion Locked

Data loss when copying files

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I experience random loss of data when merely copying files via Telnet on the Redhat Linux 7.2 system of my ISP using Bash. My ISP cannot solve the problem. Maybe you've got a hint?

I can reproduce the problem using the following test script:===== begin script =====
#!/bin/bash

ORIGINAL=./Trompmail.html.original
VICTIM=./Trompmail.html
TEMPFILE=~/temp/update.$(date '+%H%M%S').$$.0

cp $ORIGINAL $VICTIM

i=10000
while [ $i -gt 0 ]
do
sed 's/\([^ \t]\) *\(\.\,\!\?\;\:\)/\1\2/g' $VICTIM >$TEMPFILE
cp $TEMPFILE $VICTIM
ls -l $VICTIM | grep -w 0
if [ $? -eq 0 ]
then
i=0
fi
i=$(($i-1))
done

if [ $i -eq 0 ]
then
echo Success
else
echo Failure
fi
====== end script ======
After a while, the script reports Failure because the file size is zero. Before that happens, cp may report the following problems:

"cp: cannot create regular file `./Trompmail.html': Input/output error"

or

"cp: closing `./Trompmail.html': Input/output error"

but these messages do not imply that the file size has reduced to zero.

What's happening? More importantly, what can I do to prevent this problem? (The original script is quite lengthy, so inserting sleep 1 commands is not an option.)

4 replies

by skizz

You could try removing both the copy statements.
They aren't really needed. Just perform the sed on $ORIGINAL and output it to $VICTIM

by rotaluclac

I know the copy statements are not needed. The entire script is not needed. It is a DEMO script, intended to demonstrate the problem.

The question is: WHY is the file size reduced to zero? WHY do I get those error messages?

This discussion is closed to new replies.