Adobe Campaign is one of the most robust marketing automation tools available today. From designing, building, testing, and automating your marketing campaigns, you can get a lot accomplished on a single platform. Think centralized access to up-to-date customer profiles, cross-channel marketing, mass mailing, ability to track each email, push notifications, and content customization, Adobe Campaign ticks every box.

While the simple drag-and-drop interface makes workflow creation quite easy, what interests me more as a developer is that I can make use of a JavaScript or a shell script when I’m dealing with a complex requirement.  

The JavaScript activity in Adobe Campaign allows JavaScript code to be executed for operations such as parsing files, defining configurations and operation flows, computing values, and passing data between different operations. SQL and shell commands can also be executed using the JavaScript activity. 

With Shell Script, you can avoid the bulky JavaScript coding for simple operations. For example, you can split a file into chunks with a single command in shell script. To do the same using JavaScript, it would take many lines of code. Also, when you have to run multiple shell commands or scripts of higher complexity (like using aws cli commands for data management with AWS cloud), the shell script activity in Adobe Campaign is more effective. 

Running Shell Script in Adobe Campaign Classic V7

Unlike Adobe Campaign V6, the shell script activity in Adobe Campaign Classic v7 is not built-in. There are two options to access shell script in v7. 

Option 1

If you have a previous version of Adobe Campaign, just copy the activity from the previous version to the current version. 

Option 2

If you don’t have access to an older version of Adobe Campaign, these are the steps you can take: 

1. Create a new workflow and open it. Right click and select Edit XML source... from the menu. 

Accessing Shell Scripting in Adobe Campaign Classic V7

Fig. 1. Selecting Edit XML structure

The workflow’s XML source code will be displayed.

Step to access shell script in Adobe Campaign Classic

  Fig.2. XML source code of the newly created workflow

2. Copy the code snippet.


 
   
     
     
       
     
 

3. Paste the code in the workflow XML, just below the ‘Modified by’ tag (as shown in the below image) and click Ok.

Accessing shell script in Adobe Campaign V7

Fig.3. Workflow XML with shell script code added 

4. The workflow should now have the shell script activity generated. Click Save.

Generating shell script activity in Adobe Campaign V7

Fig.4. Shell script activity appears on the workflow

Once the shell script activity is added to a workflow, just copy-paste it to other workflows. This will help you avoid repeating the above steps.

Now that you have added the shell script, go ahead and use the commands just as you would in a normal bash terminal.

Running shell script in Adobe Campaign v7
Fig.5. A sample shell script

You can also use JavaScript variables inside the shell script.

Running shell script in Adobe Campaign
Fig.6. Shell script with JS variables

Viewing Console Output When Using Shell Script

One of the drawbacks with shell script is that the console output cannot be viewed directly in the audit log. There is a workaround for that too.

In your workflow, where you want to display the logs from shell script activity, 

  1. Add a JavaScript activity right after the shell script activity (Refer step 1 in the below screenshot). 
  2. Use the logInfo() function to print the two variables vars.output and vars.lastError to the audit log (Refer step 2 in the below screenshot). The two default variables vars.output and vars.lastError represent the console output and error, if any, in the last activity execution respectively. 
Steps to view console output When using shell script in Adobe Campaign

Fig.7. Steps to view console output

Make sure that the JavaScript activity is added right next to your shell script activity.

Nifty Shell Commands in Adobe Campaign

With shell script, you can overcome many roadblocks in technical workflow development, which would otherwise require assistance from the Adobe support team. Here are some useful shell commands that we have used in our technical operations in Adobe Campaign Classic v7.

  • gpg command to encrypt and decrypt files

Compliance with data privacy regulations is a major concern for organizations. While implementing Adobe Campaign for clients in Europe where GDPR is in force, we add an extra layer of protection to First Degree Personal Information by encrypting the file containing the data. GnuPrivacy Guard (gpg) encryption is one of the widely used encryption methods. 

gpg --recipient  --encrypt 
gpg --decrypt 
  • Curl command for REST API call 

curl is a great command line tool that allows transfer of data to or from a server. In the technical workflows we develop, there is often a need to call external REST APIs hosted by our customers’ upstream systems. In such cases, we use the curl command to check whether the API call is successful or not. You can use the same command if you don’t need to handle the JSON object obtained in API response.
NOTE: For more complex operations, JS and  HttpClientReques are recommended. However, HttpClientRequest requires you to whitelist the domain in serverconf.xml.

curl -d '' -H 'Content-Type: application/json'   -o out.json 2>>errorlog.txt
  • Piping multiple commands

During technical workflow development, you may receive files with unwanted strings or patterns. Since correction or adjustment at the vendor-side is expensive, we manipulate the files at our end in Adobe Campaign. We use a series of sed operations chained with the pipe operator, which allows us to perform multiple replacements in a single line. The sample script displayed below shows how to remove blank lines and convert a comma-separated file to a tab-separated file.

cat SampleFile.csv | sed 's/,/\t/g' | sed '/^$/d'> tabSeparated.csv
  • sed,split,head,gzip etc for file manipulations

Most of our technical operations involve either downloading files from multiple upstreams or uploading extracted content to external servers or Amazon S3 buckets. In certain situations, these files have to be modified to facilitate their use. You can split large files into chunks using split command, remove/replace certain characters in the file (like Byte Order Mark from UTF8 files) using sed command and regex, extract top or bottom ‘n’ lines of large files using head command, zip or /unzip files using gzip command, and so on.

split -d -l   
cat  | sed -e '1s/^\xef\xbb\xbf//' > 
cat LargeFile.csv | head -n 10 > Sample.csv
gzip -k userlist.csv
  • rm command to remove files from SFTP path 

Before downloading files from S3 bucket or other external servers, you have to check for duplicate files in the folder from which you are downloading. Duplicate files result from sample files that are transferred to SFTP for testing purposes but are not removed once the testing is over. It may not always be possible to manually remove files or folders from SFTP path using FTP UIs due to lack of permission to delete files and folders. In such cases, shell commands come handy. Important: Rollback is not supported in shell script. So double check the file path you specify. If you specify a wrong path, the files or folders will be deleted without confirmation.  

rm -rf /sftp/yourpath

These are not the only commands in the shell script activity in Adobe Campaign. There are many more useful and powerful shell commands out there. Based on your requirements, you can identify and use scripts that best suit your needs. 

Don’t Rush. Test Before You Apply!

We have seen how useful shell scripting is. But exercise caution by testing your command in a local machine before executing it in Adobe Campaign. You will not be prompted for confirmation or allowed to roll back your changes. Unless you are careful, commands such as deletion or move could result in unwanted outcomes. If you do not have access to an Ubuntu machine, you can install git on your Windows machine. Git-bash will help you test most of the shell scripts on Windows. 

If you are unsure of how you can use scripting to your advantage in Adobe Campaign or struggling to develop a technical workflow to solve a specific requirement, our Adobe Campaign team can help you out. From designing and building your marketing automation solution to running, managing, and optimizing your campaigns, we, as an experienced marketing automation consultant, can ensure you make the best use of Adobe Campaign.