#!/bin/bash # Config parameters VISID_VER="2.5.0" ORG_ID=[ORDID] COOKIE_JAR="cookies.txt" ECID_JSON="ecid.json" # Check needed programs type jq >/dev/null 2>&1 if [ $? -ne 0 ] ; then echo >&2 "This script requires 'jq'. Install it before proceeding." exit 1 fi type curl >/dev/null 2>&1 if [ $? -ne 0 ] ; then echo >&2 "This script requires 'curl'. Install it before proceeding." exit 1 fi # Check if we need to refresh the ECID (only every 7 days) if [ -r "$ECID_JSON" ] ; then TTL=$(jq --raw-output '.id_sync_ttl' "$ECID_JSON") TTL=$(( TTL / 60 )) if ! test `find "$ECID_JSON" -mmin +$TTL` ; then echo "No need to refresh the ECID" cat "$ECID_JSON" echo exit 0 fi fi # Build the URL URL="https://dpm.demdex.net/id" URL="$URL?d_visid_ver=$VISID_VER" URL="$URL&d_fieldgroup=MC&d_rtbd=json&d_ver=2&d_verify=1&d_nsid=0" URL="$URL&d_orgid=$ORG_ID" if [ -r "$ECID_JSON" ] ; then MID=$(jq --raw-output '.d_mid' "$ECID_JSON") URL="$URL&d_mid=$MID" fi URL="$URL&ts=$(date +%s)" # Make the request and store the JSON response in pretty format TMP=`mktemp` curl --location --cookie "$COOKIE_JAR" --cookie-jar "$COOKIE_JAR" --output "$TMP" --verbose "$URL" jq . "$TMP" > "$ECID_JSON" rm "$TMP" # Echo the results cat "$ECID_JSON" echo -n "MID=" jq --raw-output '.d_mid' "$ECID_JSON" echo -n "BLOB=" jq --raw-output '.d_blob' "$ECID_JSON" echo -n "DCS REGION=" jq --raw-output '.dcs_region' "$ECID_JSON"