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.0
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.0 -
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
0 -
Hi, Ben!
Thank you for the suggestion. Tried with the error dump approach but still no error was found.
Thanks,
Leah
0 -
Can you post the whole script (with any credentials removed)?
0 -
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"
#Uploadfor 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}"
fiif [ "${KeyStorePath}" ]; then
Credentials="-keystore ${KeyStorePath} -keystorepass ${KeyStorePass} -keystorealias ${KeyStoreAlias}"
fiecho cd "`dirname "$0"`"
cd "`dirname "$0"`"
if [ ! -f AnaplanClient.sh ]; thenecho "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"
done0 -
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}"0 -
The "exec" should be removed, though - it will cause the shell running the script to terminate abruptly
0 -
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
0 -
As Ben mentions, remove the "exec". Sorry, copied it from another script where its not looping! Well spotted @ben_speight0
-
Thank you so much @MarkWarren , @ben_speight ! It is now working.
0