Inserting adsense code to multiple files...

Here's a quick bash script that I wrote to add adsense code just before the closing body tag in several accounts with the same file name. Could be modified to take the file names as the last argument if different.

Note: replace the UA-####### with your particular ID number assigned by adsense.

#!/bin/bash
# insert_adsense.sh
# usage: ./insert_adsense.sh {account} {count}

ACCOUNT=$1
COUNT=$2
FILE=/home/${ACCOUNT}/public_html/index.inc.php

ADSENSE="

<script src=\"http://www.google-analytics.com/urchin.js\" type=\"text/javascript\">
</script>
<script type=\"text/javascript\">
_uacct = \"UA-#######-${COUNT}\";
urchinTracker();
</script>

"

cp $FILE $FILE.bak

replace "</body>" "${ADSENSE}</body>" -- $FILE

exit 0

Comment