Automic Workload Automation

 View Only
Expand all | Collapse all

Listing objects in a transport case export file

Michael A. Lowry

Michael A. LowryMar 13, 2014 01:40 PM

  • 1.  Listing objects in a transport case export file

    Posted Mar 12, 2014 11:58 AM

    I would like to find a general method for listing the objects in a file unloaded from the transport case using theucybbdunprogram (hereinafter, referred to simply as thetransport case). I have not found a straightforward way to do this, and I would like to enlist the help of others to find a solution.

    One of the tools in our deployment process relies on the ability to list objects of a certain type in the transport case. For instance, we need to get list of all of the JOBP objects and JSCH objects. I found a very kludgey way of doing this, using the change program. If I know something about the object names, I can contrive a change rule that will apply to all objects of a certain type, but will actually make no changes. E.g.,

     

    REPLACE_PART JOBS, * , OBJECT_NAME, ABC, ABC

    If we know that the jobs’ names will all contain the string ABC,the output from ucybchng will include the names of the objects that were found. However, if the objects’ names are not known, this approach will not work. Is there another way, using ucybchng or some other program, to list all objects in the transport case of a certain type?

    In another part of our deployment process, we check to make sure objects in the transport case are named according to our strict naming convention. Last year, a UC4 consultant helped us develop a tool to check for compliance with the naming convention. This tool uses a very simple approach. It looks at all lines in the transport case that begin with F003C. The consultant apparently believed that lines beginning with this string of characters always corresponded to object names. Unfortunately, this is not always true. We have discovered that Script lines of jobs also begin with F003C. Is there a more specific way of identifying the lines that correspond to object names?

    Thanks in advance for any ideas or feedback.

    Regards,

    Michael L.


    P.S. For those who are interested, I will include the Bash script below that we use to lists objects of a certain type in the transport case.

    #!/bin/bash
    # List objects in the transport case. This script takes three arguments:
    # 1. the short name of the object type, e.g., JOBP or SCRI
    # 2. the object name prefix -- essentially any part of the object name that will
    # match all objects
    # 3. the fully qualified path of the transport case file

    function handle_ucybchng_rc {
    #Handle return code of change program.
    case $RC in
    0)
      echo "Change program ended successfully."
      ;;
    1)
      echo "ERROR: The transport file does not exist or cannot be opened."
      ;;
    2)
      echo "ERROR: The script file does not exist or cannot be opened."
      ;;
    3)
      echo "ERROR: The transport and the script file do not exist or cannot be opened."
      ;;
    4)
      echo "ERROR: The output file cannot be opened."
      ;;
    5)
      echo "ERROR: The script file includes an error (see messages above)."
      ;;
    *)
      echo "ERROR: Unknown error."
      ;;
    esac
    return $RC
    }

    OBJ_TYPE=$1
    PREFIX=$2
    TRANSPORT_CASE=$3
    TEMP_DIR=/tmp
    UC4_UTILITY_BIN_DIR=/usr/local/ebm/uc4/utilities/bin
    LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${UC4_UTILITY_BIN_DIR}
    changefile_template="changefile_template.$$.txt"
    changefile_replace="changefile_replace.$$.txt"
    changefile="changefile.$$.txt"
    objectlist="objectlist_${OBJ_TYPE}.$$.txt"
    ucybchng_tmp="ucybchng_tmp.$$.txt"
    ucybchng_log="ucybchng_log.$$.txt"
    echo ""
    echo "============================================================================="
    echo "Running change program to check transport case for $OBJ_TYPE objects."
    echo "-----------------------------------------------------------------------------"
    cd ${TEMP_DIR}
    echo 'REPLACE_PART **OBJECT_TYPE**, * , OBJECT_NAME, "**PFX**.", "**PFX**."' > ${changefile_template}
    echo s:\\*\\*OBJECT_TYPE\\*\\*:${OBJ_TYPE}:g > ${changefile_replace}
    echo s:\\*\\*PFX\\*\\*:${PREFIX}:g >> ${changefile_replace}
    sed -f ${changefile_replace} < ${changefile_template} > ${changefile}
    ${UC4_UTILITY_BIN_DIR}/ucybchng -b -1${TEMP_DIR}/${changefile} -2${TRANSPORT_CASE} -3${TEMP_DIR}/${ucybchng_tmp} 2>&1 > ${ucybchng_log}
    RC=$?
    echo "Change program ended with exit code ${RC}."
    #Handle return code of change program.
    handle_ucybchng_rc

    # Parse change program output to extract object names
    awk  -F:F003C -v ORS=$'\n' '/New line:F003C/ { print $2 }' ${ucybchng_log} > ${objectlist}

    # Print report
    echo "-----------------------------------------------------------------------------"
    echo "Transport case      : ${TRANSPORT_CASE}"
    echo "Object type         : ${OBJ_TYPE}"
    echo "Object name pattern : ${PREFIX}"
    echo "-----------------------------------------------------------------------------"
    echo "Object list file    : ${objectlist}"
    echo "-----------------------------------------------------------------------------"
    cat ${objectlist}
    echo "============================================================================="

    # Remove temporary files
    rm ${ucybchng_log} ${ucybchng_tmp}
    rm ${changefile_template} ${changefile_replace} ${changefile}


  • 2.  Listing objects in a transport case export file

    Posted Mar 12, 2014 07:17 PM

    I don't know if this is exactly what you are looking for, but a SQLI variable object could run this sort of query for you;

    select OH_Client
         , OH_OType
         , OH_Name
    from dbo.oh
    where OH_expflag = '1'
    and   OH_OType   = 'JOBS'
    and   OH_Client  = 401



  • 3.  Listing objects in a transport case export file

    Posted Mar 13, 2014 02:37 AM

    Thanks, but that is not what I’m looking for. I need a way to list the objects in the exported file, not the DB.



  • 4.  Listing objects in a transport case export file

    Posted Mar 13, 2014 05:03 AM

    Hi Michael, in the transport case the object type is defined one line above the object name (see my examples below). I never used this Information productively, so I do not know if you can be sure that these control tags only occur at this point and not in the script section or any other place. But I think the combination of F002C<Type> and F003C  and control tags are a good way to list the objects their types contained in a case.

    F002CJOBS
    F003CJOB.TEST
    F002CJOBP
    F003CPLAN.TEST
    F002CJOBF
    F003CFILE.TEST
    F002CSCRI
    F003CSCRI.TEST





  • 5.  Listing objects in a transport case export file

    Posted Mar 13, 2014 05:31 AM

     

    Hi Michael, in the transport case the object type is defined one line above the object name. ... I think the combination of F002C<Type> and F003C  and control tags are a good way to list the objects their types contained in a case.

    F002CJOBS
    F003CJOB.TEST
    ...

    Thanks. That is helpful. Using your insight, I wrote a simple script that will list all objects of a given type in a transport case.

    #!/bin/bash
    # List objects in transport case
    TRANSPORT_CASE=$1
    OBJ_TYPE=$2
    egrep F002C${OBJ_TYPE} -A1 ${TRANSPORT_CASE} |\
    awk -FF003C -v ORS=$'\n' '/^F003C/ { print $2 }'



  • 6.  Listing objects in a transport case export file

    Posted Mar 13, 2014 05:34 AM

    You can try this one. It outputs Client, OType and Name of all objects in the transport case. It only works for transport cases, not for data files which have a slightly different structure.


    usage()
    {
        echo "Usage: $0 <transport case>"
    }

    #this function outputs the found OH record. Adapt its formatting to your needs
    printobject()
    {
        echo "$1;$2;$3"
    }

    #check cmdline parameters
    if [[  $# -ne 1 ]]; then
        usage
        exit 1
    fi

    #check if transport case exists
    trans=$1
    if [[ ! -f "$trans" ]]; then
        echo "Transport Case '$trans' does not exist"
        usage
        exit 2
    fi

    status=1
    ohname=""
    ohotype=""
    ohclient=""


    cat "$trans" | sed -e "s/\r//" | grep -e "^T" -e "^F00[123]" -e "^R$" | \
    while read x; do
        case $status in
        1)
            if [[ "$x" == 'TOH' ]]; then
                # here starts records for table OH
                status=2
            fi
            ;;
        2) 
            #read fields only if we are in table OH (after record 'TOH')
            case "${x:0:4}" in
            'F001') ohclient="${x:6}";;
            'F002') ohotype="${x:5}";;
            'F003') ohname="${x:5}";;
            'R')
                printobject $ohclient $ohotype $ohname
                ohclient="0000"
                ohotype=""
                ohname=""
                status=1
                ;;
            esac
            ;;
        esac
    done





  • 7.  Listing objects in a transport case export file

    Posted Mar 13, 2014 05:45 AM

    I thought there might be something special about the three-line F001–F002–F003 combination. This script is exactly what we needed. Thanks,Christian_Bartl_212!



  • 8.  Listing objects in a transport case export file

    Posted Mar 13, 2014 10:38 AM

    I updated the script a bit for our needs.

    Changes:

    • object titles and primary folder locations are now printed too
    • tab-delimited output -- necessary because object titles may contain other separators
    #!/bin/bash
    # list_objects_in_transport_case.sh
    #
    # Description
    # This script lists all objects in a transport case export file, in the following
    # format:
    # CLIENT        TYPE    NAME    TITLE   FOLDER
    #
    # where:
    # CLIENT is the UC4 client number;
    # TYPE is the object type;
    # NAME is the object name;
    # TITLE is the object title; and
    # FOLDER is the primary folder location.
    #
    # The fields are tab-delimited: a single tab separates fields on each line.
    #
    # Usage
    # list_objects_in_transport_case.sh <transport case>
    #
    # Revision history
    # Version       Date            Author
    # 1.0.0.0       2014.03.13      Christian Bartl
    # Initial version from post on Automic forum:
    # http://community.automic.com/discussion/comment/1533/#Comment_1533
    #
    # 1.0.1.0       2014.03.13      Michael A. Lowry
    # Print object titles & folders, and print tab-delimited output.

    usage()
    {
        echo "Usage: $0 <transport case>"
    }

    #this function outputs the found OH record. Adapt its formatting to your needs
    printobject()
    {
        echo "$1;$2;$3;$4;$5"
    }

    #check cmdline parameters
    if [[  $# -ne 1 ]]; then
        usage
        exit 1
    fi

    #check if transport case exists
    trans=$1
    if [[ ! -f "$trans" ]]; then
        echo "Transport Case '$trans' does not exist"
        usage
        exit 2
    fi

    status=1
    ohname=""
    ohotype=""
    ohclient=""

    cat "$trans" | sed -e "s/\r//" | grep -e "^T" -e "^F00[1235]" -e "^R$" -e '^O\\' | \
    while read x; do
        case $status in
        1)
            if [[ "$x" == 'TOH' ]]; then
                # here starts records for table OH
                ohfolder=""
                status=2
            fi
            ;;
        2)
            #read fields only if we are in table OH (after record 'TOH')
            case "${x:0:4}" in
            'F001') ohclient="${x:6}";;
            'F002') ohotype="${x:5}";;
            'F003') ohname="${x:5}";;
            'F005') ohtitle=$(echo $x | cut -c6- );;
            'R') ;;
            O*)
                # Remove folder titles from the folder path.
                ohfolder="/$(echo $x | sed -re 's/\{(([^\{\}])*?)?\}/\//g' | cut -c2- )"
                tab=$'\t'
                echo "${ohclient}${tab}${ohotype}${tab}${ohname}${tab}${ohtitle}${tab}${ohfolder}"
                ohclient="0000"
                ohotype=""
                ohname=""
                ohtitle=""
                status=1
                ;;
            esac
            ;;
        esac
    done
    @Christian Bartl, I made some educated guesses here. If you see an obvious mistake, feel free to correct it. :smile: 



  • 9.  Listing objects in a transport case export file

    Posted Mar 13, 2014 11:03 AM

    Note: I have never tried to transport objects that have no folder location (objects that appear in <No Folder> in the GUI). Depending on how such objects' folder locations are encoded in the transport case, these object might pose a problem for my version of the script.



  • 10.  Listing objects in a transport case export file

    Posted Mar 13, 2014 11:57 AM

    Hello Michael,

    objects in <No Folder> to not have an O-Record in the transport case. Here are the required modifications:

    #!/bin/bash
    # list_objects_in_transport_case.sh
    #
    # Description
    # This script lists all objects in a transport case export file, in the following
    # format:
    # CLIENT        TYPE    NAME    TITLE   FOLDER
    #
    # where:
    # CLIENT is the UC4 client number;
    # TYPE is the object type;
    # NAME is the object name;
    # TITLE is the object title; and
    # FOLDER is the primary folder location.
    #
    # The fields are tab-delimited: a single tab separates fields on each line.
    #
    # Usage
    # list_objects_in_transport_case.sh <transport case>
    #
    # Revision history
    # Version       Date            Author
    # 1.0.0.0       2014.03.13      Christian Bartl
    # Initial version from post on Automic forum:
    # http://community.automic.com/discussion/comment/1533/#Comment_1533
    #
    # 1.0.1.0       2014.03.13      Michael A. Lowry
    # Print object titles & folders, and print tab-delimited output.

    usage()
    {
        echo "Usage: $0 <transport case>"
    }

    #check cmdline parameters
    if [[  $# -ne 1 ]]; then
        usage
        exit 1
    fi

    #check if transport case exists
    trans=$1
    if [[ ! -f "$trans" ]]; then
        echo "Transport Case '$trans' does not exist"
        usage
        exit 2
    fi

    status=1
    ohname=""
    ohotype=""
    ohclient=""
    ohtitle=""
    ohfolder="<nofolder>"


    cat "$trans" | sed -e "s/\r//" | grep -e "^[TS]" -e "^F00[1235]" -e "^R$" -e '^O\\' | \
    while read x; do
        case $status in
        1)
            if [[ "$x" == 'TOH' ]]; then
                # here starts records for table OH
                #ohfolder=""
                status=2
            fi
            ;;
        2)
            #read fields only if we are in table OH (after record 'TOH')
            #echo $x
            case "${x:0:4}" in
            'F001') ohclient="${x:6}";;
            'F002') ohotype="${x:5}";;
            'F003') ohname="${x:5}";;
            'F005') ohtitle="${x:5}";;#$(echo $x | cut -c6- );;
            'R')    status=3;;
            esac
            ;;
        3)
            #read optional O-Record (Ordner = Folder in German)
            if [[ "${x:0:1}" = 'O' ]]; then
                ohfolder="/$(echo $x | sed -re 's/\{(([^\{\}])*?)?\}/\//g' | cut -c2- )"
            fi
            tab=$'\t'
            echo "${ohclient}${tab}${ohotype}${tab}${ohname}${tab}${ohtitle}${tab}${ohfolder}"
            ohname=""
            ohotype=""
            ohclient=""
            ohtitle=""
            ohfolder="<nofolder>"
            if [[ "$x" == 'TOH' ]]; then
                #new OH records starts
                status=2
            else
                #any other record
                status=1
            fi
            ;;
        esac
    done





  • 11.  Listing objects in a transport case export file

    Posted Mar 13, 2014 01:40 PM

    Perfect. Thanks again.



  • 12.  Listing objects in a transport case export file

    Posted Mar 17, 2014 05:41 PM

     

    I found this thread to be very interesting.  I hadn't thought of writing a simple tool to expose the contents of a transportcase file.  So I wrote my own as a VBS script since we are running on windows.  Currently writes its output to a notepad file, but one could easily change it to write the report to a different destination.

     

    ' Written/tested by Pete Wirfs on 03/14/2014 ' Just drag/drop your TRANSPORTCASE file onto this script to get ' get a report of its contents.   set args  = WScript.Arguments   if args.count = 0 then      msgbox("Drag/Drop a transportcase file onto this program to generate a report of its contents. ("& Wscript.ScriptName & ")")      wscript.quit   end if   FileIn    = args.item(0) ' Use these three lines if you want the report to ' be dropped into the same folder as the transportcase file;   ' Temp      = strReverse(FileIn)   ' Temp      = mid(Temp,instr(Temp,"\"))   ' Temp      = strReverse(Temp) ' Otherwise, just use this target folder;   Temp      = "c:\temp\"   FileOut   = Temp & "TCReport.txt" Const ForReading = 1 Const ForWriting = 2 ' reads the file into an array   Set objFSO = CreateObject("Scripting.FileSystemObject")   Set objFile = objFSO.OpenTextFile(FileIn, ForReading)   strText = objFile.ReadAll   objFile.Close   strNewText = FormatDateTime(Now) & vbCrLf & "Contents of TransportCase file: " & vbCrLf & FileIn & vbCrLf & vbcrlf & "CLIENT" & vbtab & "TYPE" & vbtab & "OBJECT" & vbcrlf   arrLines = Split(strText,vbCrLf) ' loops through the array for each strLine in arrLines   if strLine = "TOH" then  ' NEW OBJECT      if strCLIENT <> "" then         WriteLineToReport      end if      strCLIENT = ""      strTYPE   = ""      strNAME   = ""      strTITLE  = ""      strPATH   = ""   end if   if mid(strLine,1,4) = "F001" and strCLIENT = "" then      strCLIENT   = mid(strLine,6)   end if   if mid(strLine,1,4) = "F002" and strTYPE = "" then      strTYPE     = mid(strLine,6)   end if   if mid(strLine,1,4) = "F003" and strNAME ="" then      strNAME     = mid(strLine,6)   end if   if mid(strLine,1,4) = "F005" and strTITLE = "" then      strTITLE    = mid(strLine,6)   end if   if mid(strLine,1,2) = "O\" then      strPATH     = mid(strLine,3)      do while instr(strPATH,"{")
            strPATH  = mid(strPATH,1,instr(strPATH,"{") - 1) & mid(strPATH,instr(strPATH,"}") + 1)
         loop  end if next if strCLIENT <> "" then    WriteLineToReport end if ' write the report to disk   strNewText = strNewText & vbCrLf & vbCrLf & "End of report"   Set objFile = objFSO.OpenTextFile(FileOut, ForWriting, True)       objFile.Write strNewText       objFile.Close ' launch notepad   Dim objShell   Set objShell = CreateObject("WScript.Shell")   objShell.Run("notepad " & FileOut) sub WriteLineToReport     strNewText  = strNewText & vbCrLf & strCLIENT & vbtab & strTYPE & vbtab & strPATH & "\" & strNAME end sub


  • 13.  Listing objects in a transport case export file

    Posted Jun 20, 2014 12:28 PM

     

    Are the paired curly-braces in the O records necessary?

    E.g, can we replace
    O\APPS{}\ARP{}\UAT1{}\COMMON{}
    with
    O\APPS\ARP\UAT1\COMMON
    ?

    We are using ucybchng to change things in transport cases whenever possible, but in some cases, we must change things using an external source code management system. This system does simple find-and-replacement of strings. It does not know about the folder titles and does not try to insert them.

    My initial test showed no problems, but I thought I should double-check.


  • 14.  Listing objects in a transport case export file

    Posted Jun 21, 2014 11:37 AM

    The braces are optional. The only requirement is that you have to add either all within an O-record, or none.



  • 15.  Listing objects in a transport case export file

    Posted Jun 23, 2014 03:47 AM

    Ok, that’s good to know. As I understand your answer, this means that if we replace part of a folder path, and end up removing one or more pairs of curly braces, we must either remove the remaining pairs of braces from the O record, or insert them where they are missing.

    So both

    O\APPS\ARP\UAT1\COMMON{}
    and
    O\APPS{}\ARP{}\UAT1\COMMON{}
    would not work.

    Is this correct?

    One more thing: are you talking about your script, or the ucybdbld program?



  • 16.  Listing objects in a transport case export file

    Posted Jun 23, 2014 06:08 AM

    You understood correctly: All parts within one O-record must use the same format. You exampled are both incorrect (i.e. undefined behaviour in ucybdbld). I did not test it with my script.



  • 17.  Listing objects in a transport case export file

    Posted Jun 23, 2014 08:19 AM

    Ok, that is good to know. For what it’s worth, ucybdbldsuccessfully loaded a transport case that had many paths with one missing set of braces, e.g.,

    O\APPS{}\UC0\MAL{}\TEST{}\JSCH{}

    I discovered, however, that the script you wrote is unable to properly read paths like this. Specifically, theread in the script appears to parse the backslashes as escape characters, which causes the variablexto contain something like this:

    OAPPS{}UC0MAL{}TEST{}JSCH{}

    The regexp replaces matched pairs of curly braces (containing any number of non-curly-brace-characters) with slashes, so it results in output like this:

    0100    JSCH    UC0.MAL.JSCH2           /APPS/UC0MAL/TEST/JSCH/
    I do not know a good way around this problem. If you can think of something, please let me know.

    For now, where I just need a list of all of the folders in the transport case,  I will use a simpler method that avoids the problem by never reading the line into a variable, and by replacing actual backslashes with slashes instead of relying on the presence of matched pairs of curly braces.
    awk '/^O/ {print $1}' $trans | sort | uniq | sed -e 's/\\/\//g' | sed -re 's/\{(([^\{\}])*?)?\}//g' | cut -c2-
    I will also try to move away from the simple sed-like replacements in our source code management system, and to use ucybchng instead. In the mean time, I will advise users not to change multiple levels of the folder path at once. The only drawback of this is that the matching will be less specific, and may change other folders by mistake.

    Thanks again for your feedback and help.













  • 18.  Listing objects in a transport case export file

    Posted Jun 23, 2014 08:24 AM

    By the way, I can never remember regular expression syntax without reaching for a book, so I was very glad to findRegExr, a helpful tool that shows exactly how each part of a expression functions. Recommended!

    ywkj56jcrot9.pnghttps://us.v-cdn.net/5019921/uploads/editor/f3/ywkj56jcrot9.png" width="706">
    Here is my expression for matching folder titles and enclosing curly braces.


  • 19.  Listing objects in a transport case export file

    Posted Jun 26, 2014 04:53 AM

    I just realized that my current approach is not really sufficient because it lists all O records, and not just primary ones. For example, if an object has the following O records

    O\APPS{}\UC0{}\MAL{}\TEST{}
    O\APPS{}\UC0{}\MAL{}\TEST1{}

    this means that the object is located in/APPS/UC0/MAL/TESTand that a link to the object resides in/APPS/UC0/MAL/TEST1. My simply awk command above will not distinguish between the two O records.

    I need to distinguish between primary object location, and the location of any links because the script will delete objects in the target folder, and it must not delete objects in any folder other than the primary object location.

    So, I need to find a way to list only the first O record for each object. I guess a more complex awk command will do the trick. E.g., match lines beginning with O that follow a line that does not begin with O.  I will look into this when I have time. If anyone is good with awk and knows how to do this, please let me know.

    Update: I asked this question on Stack Overflow. I will post the best answer.


  • 20.  Listing objects in a transport case export file

    Posted Jun 26, 2014 07:29 AM

    Stack Overflow delivers once again! Here is the updated command to list primary folder locations in a transport case:

    awk '/^O/{if(seen==0){seen=1;print $0}} !/^O/{if (seen==1) {seen=0}}' $trans |\
     sort | uniq | sed -e 's/\\/\//g' | sed -re 's/\{(([^\{\}])*?)?\}//g' | cut -c2-
    Thanks to Jidder for the answer to the awk question.

    Update 2014.06.27: The original command above produced incorrect output sometimes. I have updated the command with a corrected version that should work reliably.


  • 21.  Listing objects in a transport case export file

    Posted Jun 26, 2014 11:32 AM

    Incidentally, with a bit of modification, the above awk command could be made to strip out all links, leaving only primary folder locations. This would go part of the way toward addressingucybdbld’s somewhat limited capabilityin dealing with object folder locations.

    E.g.,

    awk '/^O/{if(seen==0){seen=1;print $0}} !/^O/{if (seen==1) {seen=0} print $0}' $trans > $newtrans




  • 22.  Listing objects in a transport case export file

    Posted Jun 27, 2014 08:36 AM

    Ok, I figured out how to tellreadnot to interpret backslashes as escape characters:read -r.

    #!/bin/bash
    # list_objects_in_transport_case.sh
    #
    # Description
    # This script lists all objects in a transport case export file, in the following
    # format:
    # CLIENT        TYPE    NAME    TITLE   FOLDER
    #
    # where:
    # CLIENT is the UC4 client number;
    # TYPE is the object type;
    # NAME is the object name;
    # TITLE is the object title; and
    # FOLDER is the primary folder location.
    #
    # The fields are tab-delimited: a single tab separates fields on each line.
    #
    # Usage
    # list_objects_in_transport_case.sh <transport case>
    #
    # Revision history
    # Version       Date            Author                  Comments
    # 1.0.0.0       2014.03.13      Christian Bartl         Initial version
    #   http://community.automic.com/discussion/comment/1533/#Comment_1533
    # 1.0.0.1       2014.03.13      Michael A. Lowry        Print object titles & folders, and print tab-delimited output.
    # 1.0.0.2       2014.06.27      Michael A. Lowry        Use read -r instead of read to avoid interpreting backslashes

    usage()
    {
            echo "Usage: $0 <transport case>"
    }

    #check cmdline parameters
    if [[  $# -ne 1 ]]; then
            usage
            exit 1
    fi

    #check if transport case exists
    trans=$1
    if [[ ! -f "$trans" ]]; then
            echo "Transport Case '$trans' does not exist"
            usage
            exit 2
    fi

    status=1
    ohname=""
    ohotype=""
    ohclient=""
    ohtitle=""
    ohfolder="<nofolder>"

    cat "$trans" | sed -e "s/\r//" | grep -e "^[TS]" -e "^F00[1235]" -e "^R$" -e '^O\\' | \
    while read -r x; do
    #       printf "RECORD: $x"
            case $status in
            1)
                    if [[ "$x" == 'TOH' ]]; then
                            # here starts records for table OH
                            #ohfolder=""
                            status=2
                    fi
                    ;;
            2)
                    #read fields only if we are in table OH (after record 'TOH')
                    #echo $x
                    case "${x:0:4}" in
                    'F001') ohclient="${x:6}";;
                    'F002') ohotype="${x:5}";;
                    'F003') ohname="${x:5}";;
                    'F005') ohtitle="${x:5}";;#$(echo $x | cut -c6- );;
                    'R')    status=3;;
                    esac
                    ;;
            3)
                    #read optional O-Record (Ordner = Folder in German)
                    if [[ "${x:0:1}" = 'O' ]]; then
                            ohfolder="$(echo $x | sed -e 's/\\/\//g' | sed -re 's/\{(([^\{\}])*?)?\}//g' | cut -c2- )"
                    fi
                    tab=$'\t'
                    echo "${ohclient}${tab}${ohotype}${tab}${ohname}${tab}${ohtitle}${tab}${ohfolder}"
                    ohname=""
                    ohotype=""
                    ohclient=""
                    ohtitle=""
                    ohfolder="<nofolder>"
                    if [[ "$x" == 'TOH' ]]; then
                            #new OH records starts
                            status=2
                    else
                            #any other record
                            status=1
                    fi
                    ;;
            esac
    done

     

    This script works even with transport cases that have altered O records that are missing one or more matched pairs of curly braces, e.g.,
    O\APPS{}\UC0\MAL{}\TEST1{}
    Enjoy!


  • 23.  Listing objects in a transport case export file

    Posted Jun 27, 2014 09:07 AM

    Ok, I found one case in which this approach does not reliably print folder paths. If the actual folder title of a folder contains a right curly brace and no previous matching left curly brace, this will cause problems. Curly brace characters that appear in folder titles are escaped in the transport case with backslashes, but the regexps/\{(([^\{\}])*?)?\}//gdoes not exclude them. The best way to fix this would be to specifically handle escaped curly braces like\{and\}in the regexp. This is admittedly something one is not likely to encounter though, so I’m not going to bother with this at the moment.:smile: 



  • 24.  Listing objects in a transport case export file

    Posted May 24, 2017 05:46 AM
    For anyone stumbling across this old discussion thread, I thought I should provide a link to the updated transport case parsing scripts. These scripts are based on a more complete understanding of the transport case file format, and should be both more reliable and more capable.