Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Intermittent "cannot stat" errors with nested loops

    I have a bash script that has been running (on SUSE 9.3) dozens of times over the past couple of years without error. Recently it has been hitting intermittent “cp: cannot stat FILE: No such file or directory” errors.

    The script has nested loops that continuously process files in a directory until the end condition is met. There are usually between 50 and 2000 files processed per execution. About 60% of the files processed hit a condition that requires the file to be copied to a new name so the new file can be processed in a future iteration. After the file is processed it is moved to a processed directory.

    The error has not occurred more than one time per execution. Most times I can just re-run the script with the same data set and it works fine.

    The strange thing is, according to the output log, the file it is complaining about did exist in the source directory and was moved to the processed directory. Another strange thing is the location of the “cannot stat” error in the output log seems to be random. Sometimes it appears in the middle of the output for the next file or even four or five files later.

    Below is a distilled version of the code.

    Function_A() {
            local ID=$1
            local SUB=$2
            if [ $CURRENT_COUNT -lt $MAX_COUNT ]
                nohup ChildProcess $ID $SUB > "$LOG" 2>&1 &
                let CURRENT_COUNT++
                    echo "Cannot start another process right now"
            return $RC
    } # End Function_A
    # Main
    # some unrelated detail here...
    cd $DIR
    while [ $WaitingForChildrenToFinish -eq 1 ]
        # Process each file
        for FILE in `ls -tr ${MGR_ID}_*.msg 2>/dev/null`
            echo -e "\nProcessing file: \"$FILE\""
            Function_A $MGR_ID $SUBJECT
            if [ $RC -ne 0 ]
                    cp -p $FILE $RETRY
            # Finished processing this file so move it out
            mv $FILE $PROCESSED_DIR
            # some unrelated detail here...
            # End condition
            if [ $CO_END_FLAG -eq 1 ]
        done # End for each file 
        if [ $WaitingForChildrenToFinish -eq 1 ]
            echo "No files to process so sleep..."
            sleep 5
    done # End WaitingForChildrenToFinish
    Sample output looks like this:


    Processing file: "00wm4793_AAA_111.msg"
    Cannot start another process right now

    Processing file: "00wm4793_AAA_112.msg"
    cp: cannot stat `00wm4793_AAA_111.msg': No such file or directory
    Cannot start another process right now

    Any help will be appreciated. Thanks.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    You may be starting to get read errors on the drive. Unmount the file system and run "fsck -f -c" on that partition. That will check the file system and the drive with "badblocks", marking sectors that have read errors in the file system so they won't be reused.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts