Copy webcontent to Citrix NS/AG from FTP site through a Cron job
March 8, 2012
I have a customer who would like the Citrix NetScaler (Access Gateway and AAA website) website to dynamically retrieve files to show customized content without web developers entering the Citrix NetScaler on a frequent basis.
One thing you do have to remember is that over-customizing the Citrix Access Gateway portal page is in fact not supported by Citrix. I do not think there are a lot of people out there who actually know this. Now, they will not act very difficult if you alter a picture here or there or customize a little text, but be aware of over-customizing. Next to support issues, you can run into trouble when new Citrix NetScaler updates come out that are not going to be aware of your customizations.
Now, this particulair customer over-customizes a lot! What they wanted is to have an iFrame in the Access Gateway (and AAA) page which showed visitors updated news, links, RSS Feeds etc. This iFrame showed the content of a Microsoft Sharepoint environment (please, don’t ask why). We tried publishing this iFrame through Citrix Netcaler but did not work (long story short, it was because of Microsoft Sharepoint). So now we came up with the idea to copy this content periodially to the Citrix NetScaler through the use of a Cron job and FTP. (See image below).
Set up an FTP Site
Set up an FTP site with the file structure as you need it on the Citrix NetScaler. This can be any type of FTP, it doesn’t matter. Make sure the FTP site is in Read mode, no writes nessecary because we are going to get those files from Citrix NetScaler. In our case we have the following folder/file basic structure:
Create the script on NetScaler
Create a script (in our example: rssftp.sh) on the Citrix NetScaler and place it in /var/tmp (vi rssftp.sh).
The below script will create an RSS and an Images folder in the /netscaler/ns_gui/vpn/ folder if it does not exist. Pretty basic FTP stuff in there. I’m sure there a guys out there who have much better suggestions for this. If you have, let me know.
ftp -n –i <put ftp IP-Address here> <<EOF
user ftp_user ftp_password
mget -f *
mget -f *
Give the script file execute permission:
|root@ns# chmod +x rssftp.sh|
Add the following lines to the /nsconfig/rc.netscaler (create if not exist) file:
|cp /var/tmp/rssftp.sh /usr/bin/rssftp.sh
echo “0-59/15 * * * * root rssftp.sh” >> /etc/crontab
chmod a+x /etc/crontab
The manual entries created in the Crontab file are not retained after a Citrix NetScaler reboot, that’s why they need to be added to the rc.netscaler file which is a script that will run on every boot. Same goes for copying the rssftp.sh file from /var/tmp to /usr/bin. /usr/bin is not retained.
Note: in the above line this script (cron job) will run every 15 minutes, more information on the cron job scheduler can be found here:
Execute the following line:
|echo “0-59/15 * * * * root rssftp.sh” >> /etc/crontab|
Verify if the /etc/crontab file has the entry we created in the previous step by executing command “cat /etc/crontab”:
|root@ns# cat /etc/crontab
#minute hour mday month wday who command
0 * * * * root newsyslog
# time zone change adjustment for wall cmos clock,
# does nothing, if you have UTC cmos clock.
# See adjkerntz(8) for details.
1,31 0-5 * * * root adjkerntz -a
* * * * * root nsfsyncd -p
0-59/15 * * * * root rssftp.sh
Now, as a result, every 15 minutes the content of /netscaler/ns_gui/vpn/RSS and /netscaler/ns_gui_vpn/RSS/Images will be overwritten by the FTP Cron Job.
I am aware that this blog will probably not happen very much at customer’s sites, but it may come in handy when you might need bits and pieces of this solution.
Resources I used for inspiration:
Thread: Nightly Automated Backups with Cron – SCP config
HowTo: Add Jobs To cron Under Linux or UNIX?