General discussion

  • Creator
    Topic
  • #2305589

    Data loss when copying files

    Locked

    by rotaluclac ·

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

All Comments

  • Author
    Replies
    • #3532007

      Data loss when copying files

      by skizz ·

      In reply to Data loss when copying files

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

      • #3532753

        Data loss when copying files

        by rotaluclac ·

        In reply to Data loss when copying files

        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?

    • #3544453

      Reply To: Data loss when copying files

      by rotaluclac ·

      In reply to Data loss when copying files

      This question was auto-closed because it is 90 days old

    • #3544454

      Reply To: Data loss when copying files

      by rotaluclac ·

      In reply to Data loss when copying files

      This question was auto-closed because it is 90 days old

Viewing 2 reply threads