Anaplan Connect concern

Hi,

 

I am currently having issues with my script using Anaplan connect and I hope someone could help me with these:

 

1. How to do a loop in a file directory in Linux?

- I have this file directory where all my files are starting with Test prefix (Sample: "Test1, Test2, Test3"). I should be able to run all Test*.txt items in to a one import button in my model. But below script is not working. Can someone help me with the correct command to do this scenario?

 

Filename="Test.txt"

 

for i in "/home/import/"Test*.txt; do

 

Operation1="-debug -service ${ServiceUrl} -auth ${AuthUrl} -workspace ${WorkspaceId} -model ${ModelId} -chunksize ${ChunkSize} -file '${Filename}' -put ${i} -import '${ImportName}' -execute -output '${ErrorDump}'"

 

done

 

2. Even though it was executed, no error was generated in the Error dump I have set. That's why I'm not sure how to check what kind of error was made. Also, no actual data was loaded in my model.

 

Thanks,

Leah

Best Answer

  • If you've edited the example file then you need to move everything from (and including) the Operation=... downwards inside your loop, and remove the "exec" from the last command.
    If you rename Operation then any use ("${Operation}") must be renamed to match.
    Finally you'll want a separate dump file for each import run - the easiest way to do this is to set ErrorDump=${i}-dump.txt inside the loop before the operation is built up.

Answers

  • I'd start with adding this:
    echo $Operation1
    check the output looks right looks right.
    It looks okay to me, can't see any errors.

  • Hi, Mark.

     

    Thank you for your response. I've tried doing your suggestion, I can display the right command (went thru the loop) however, it is still not imported to Anaplan. Any tips what to check in Anaplan model? For this, I am just importing in a numbered list with combination of properties as unique identifier. I've tried uploading the files manually and I was able to import the expected output. So I deleted my manual import again to try the script when I tried running it again, still nothing is imported.

     

    Thanks,

    Leah

  • Hi, Ben!

     

    Thank you for the suggestion. Tried with the error dump approach but still no error was found.

     

    Thanks,

    Leah

  • Can you post the whole script (with any credentials removed)?

  • Hi, Ben!

     

    Thank you for your response. Below is my script:


    #!/bin/sh
    #This script uploads a set of files to an Anaplan Model,
    #provided by a controller script

    #*** SECTION 1 - SET VARIABLE VALUES ***

    now=$(date +'%m_%d_%Y_%T')

    #Set Anaplan Connect Variables
    AnaplanUser=""
    WorkspaceId=""
    ModelId=""
    ServiceUrl="https://api.anaplan.com"
    AuthUrl="https://auth.anaplan.com"
    ImportName="sample test"
    Filepath="/home/anaplan-connect/import"
    Filename="Test.txt"
    ChunkSize=15
    ErrorDump="/home/anaplan-connect/errorlog"


    #Upload

    for i in "/home/anaplan-connect/import/"Test*.txt; do

     

    Operation1="-debug -service ${ServiceUrl} -auth ${AuthUrl} -workspace ${WorkspaceId} -model ${ModelId} -chunksize ${ChunkSize} -file '${Filename}' -put '${i}' -import '${ImportName}' -output '${ErrorDump}'"


    #____________________________ Do not edit below this line ______________________________

    LogFile1="$now-ANAPLAN-LOG-DATA-HUB-<FILENAME>-UPLOAD.TXT"

    if [ "${AnaplanUser}" ]; then
    Credentials="-user ${AnaplanUser}"
    fi

    if [ "${KeyStorePath}" ]; then
    Credentials="-keystore ${KeyStorePath} -keystorepass ${KeyStorePass} -keystorealias ${KeyStoreAlias}"
    fi

    echo cd "`dirname "$0"`"
    cd "`dirname "$0"`"
    if [ ! -f AnaplanClient.sh ]; then

    echo "Please ensure this script is in the same directory as AnaplanClient.sh." >&2
    exit 1
    elif [ ! -x AnaplanClient.sh ]; then
    echo "Please ensure you have executable permissions on AnaplanClient.sh." >&2
    exit 1
    fi
    /bin/echo "${Operation1}"

     

    #**** SECTION #2 - Write Log File ****

    # Echo the results to the log file

    echo "*** ALL OPS COMPLETED ***" > ./BASH_STAT1.TXT

    echo "-------------------------------------" >> ./BASH_STAT1.TXT

    cat "$LogFile1" >> BASH_STAT1.TXT

    cat BASH_STAT.TXT > "$LogFile1"


    done

  • You are missing the execution of the Anaplan Client script, this should go after your /bin/echo "${Operation1}" line:

     

    Command="./AnaplanClient.sh ${Credentials} ${Operation1}"
    /bin/echo "${Command}"
    exec /bin/sh -c "${Command}"

  • The "exec" should be removed, though - it will cause the shell running the script to terminate abruptly

  • Hi, Mark!

     

    Thanks! I was able to add the last command line. It was able to work and imported to Anaplan however only one file was imported. Is there anything that I could add for the loop to work? Thanks!

     

    Regards,

    Leah

  • As Ben mentions, remove the "exec". Sorry, copied it from another script where its not looping! Well spotted @ben_speight
  • Thank you so much @MarkWarren , @ben_speight ! It is now working.