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.)