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

    Question Can't figure out the problem

    I have this Korn shell script that runs via a cron entry. It runs in a loop "watching" a specific file system for files with a certain name. The file system that it is watching is an upload file system for an FTP server. When files that are the correct name come in, it takes the extension of the file and runs several other scripts against the file with the extension as a vairable. The script looks like:

    # Function : is_file_arrived file
    # Arg(s)   : file = file to verify
    # Output   : None
    # Status   : 0 = yes file arrived, 1 = no
    # Env.     : IFA_WAIT : interval (secs) for file size check (def=5)
    is_file_arrived() {
       [ -z "$1" ] && return 1
       local file=$1
       local arrived=1
       local size1 size2
       if [ -f "$file" -a -z "$(fuser $file 2> /dev/null)" ] ; then
          size1=$(ls -l $file 2>/dev/null | awk '{print $5}')
          sleep ${IFA_WAIT:-15}
          size2=$(ls -l $file 2>/dev/null | awk '{print $5}')
          [ ${size1:-1} -eq ${size2:-2} ] && arrived=0
       return $arrived
    processFile ()
       local fileName=$1
       local fileExtension=$2
       local fileNewName="/ftp/datafiles/str${fileExtension}.asc"
       local filePrintPath="/ftp/print"
       local fileTmpPath="/ftp/tmp"
       local fileODIName="str${fileExtension}.pos"
       mv -Eignore $fileName $fileNewName      # Add status check
       prepup $fileNewName $fileExtension
       mv -Eignore  $filePrintPath/$fileODIName $fileTmpPath/$fileODIName
       save2tmp $fileExtension
       call_siu $fileExtension
    # Main Processing
    #hile :
    while [[ "$(date +%H%M)" -lt 2329 ]]
       for fileName in /ftp/datafiles/UPLOAD.[0-9][0-9][0-9][0-9]
          is_file_arrived "$fileName" && nsec=1 && processFile $fileName $fileExtens
       sleep $nsec
       case $nsec in
          1)   nsec=15;;
          15)  nsec=45;;
          45)  nsec=90;;
          90)  nsec=300;;
          300) nsec=600;;
          600) nsec=900;;
          *)   nsec=1800;;

    ... the problem is that I keep getting files that are "stuck" in the /ftp/datafiles file system. The log from the crontab states that these files have the incorrect permission for the script to process them? The wierd thing is that it happens after the script initially renames them to "str####.asc" so the cron user (which has permissions to the filesystem and the files intially) was able to rename them? The log looks like:

    + is_file_arrived /gers/genret/datafiles/UPLOAD.0043
    + nsec=1
    + processFile /gers/genret/datafiles/UPLOAD.0043 0043
    mv: 0653-401 Cannot rename /gers/genret/print/str0043.pos to /gers/genret/tmp/str0043.pos:
                 A file or directory in the path name does not exist.
    mv: /gers/genret/datafiles/str0043.asc: The file access permissions do not allow
     the specified action.
    Is it possible that the FTP user is still modifying these files when the script is trying to process them?

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Täby, Sweden
    I don't know exactly what's wrong, but I don't think that it is anything with your script, but rather filesystem permissions.

    First of all, what user is this script running as (root or an unprivileged user)?

    To answer your more immediate questions:
    Quote Originally Posted by heprox
    Is it possible that the FTP user is still modifying these files when the script is trying to process them?
    That doesn't matter the slightest. Linux has no problems at all with multiple processes manipulating a file. If a file is renamed while open for writing, the writing process will notice nothing.

    It is also not very strange that the first rename operation succeeds and the others fail. If the user that the script is running as has write access to the directory that the files are uploaded into initially, that is all which would be needed for the first rename. If that user then does not have write permission to the target directory of the second rename, that will make that operation fail. Therefore, my guess is that this is just a permissions problem.

Posting Permissions

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