#!/bin/sh cp problem with long path names/file names - Unix

This is a discussion on #!/bin/sh cp problem with long path names/file names - Unix ; Hi all I try to execute a simple shell script under UNIX/Solaris but run into a problem with too long path names (see example code below which is close to reality). Suppose that the first function call works fine but ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: #!/bin/sh cp problem with long path names/file names

  1. #!/bin/sh cp problem with long path names/file names

    Hi all

    I try to execute a simple shell script under UNIX/Solaris but run into
    a problem with too long path names (see example code below which is
    close to reality).

    Suppose that the first function call works fine but the second one
    fails. The only difference I can see is the length of the filename
    which I pass as argument to the function CopySource ().

    Are there any restrictions in the length of strings I can pass to cp?
    Or what could be the problem?

    I tried already to have the arguments split over two lines (masking
    LF) but this wasn't the solution.

    Any help very appreciated

    Patrick

    P.S: I'm an experienced programmer but not very familiar with UNIX.


    #!/bin/sh
    #
    ##----------------------------------------------------------------------
    ##CREATE FUNCTION FOR COPYING FILES
    ##----------------------------------------------------------------------

    CopySource () {
    ##--- Arguments: 1. SourceFile, 2. SourcePath, 3.
    TargetPath
    cp $2/$1 $3
    rc=$?
    echo $rc
    if [ $rc -eq 0 ]; then
    echo "Success: $1 copied"
    else
    echo "Failed: $1 not copied"
    fi
    }

    ##----------------------------------------------------------------------
    ##COPY FILES
    ##----------------------------------------------------------------------

    ##-----------------Copy Source Files ----------------------------
    SourceDir=/Slevel1/Slevel2/..../Slevel10/Slevel11
    TargetDir=/Tlevel1/Tlevel2/..../Tlevel10/Tlevel11
    mkdir $TargetDir

    CopySource F_T_A_S_M_T.dat $SourceDir $TargetDir

    CopySource File_Two_And_Some_More_Text.dat $SourceDir $TargetDir

  2. Re: #!/bin/sh cp problem with long path names/file names

    Patrick writes:
    >Hi all
    >
    >I try to execute a simple shell script under UNIX/Solaris but run into
    >a problem with too long path names (see example code below which is
    >close to reality).


    Maximum path length is file-system specific. You must use the
    'getconf' command to determine what the maximum path length is
    for the filesystem to which your copy is targetted.

    scott

  3. Re: #!/bin/sh cp problem with long path names/file names

    Path too long.

    Error cannot delete file: cannot read from source file or disk

    Cannot delete file: Access is denied

    There has been a sharing violation.

    Cannot delete file or folder The file name you specified
    is not valid or too long. Specify a different file name.

    The source or destination file may be in use.

    The file is in use by another program or user.

    Error Deleting File or Folder

    Make sure the disk is not full or write-protected and that the file is not currently in use.

    Path too deep.

+ Reply to Thread