Techie Stuff

One of the reasons I had for converting this website from a photography portfolio website to a blog was to give me a central location where I can post my thoughts and writing. At one point I was maintaining 3 different written blogs, a photoblog (which I'm still running at mydrive) and a static photography website. One of my goals for this year is to write more and a having a centralized location will help me to fulfill that goal.

During my day job I program and manage several websites. That provides a great deal of information that I can write about on a regular basis. So I recently created a Technology category that will I will use to record my thoughts about technology, software, hardware, and the like. Here is an ideal example lesson learned (or maybe re-learned.)
When writing scripts or programs you need to be careful of your variable settings. I was working on automating an ftp file upload from one unix server to another server. This is a fairly easy and straight forward shell script that I have used many times in the past. I wrote the script and ran some tests, but it was consistently failing to login to the server. It worked fine when you manually transfer the file from the command line, but wouldn't work when run as a shell script.

I normally assign variables for various components of the script so I can re-use the code in other areas and all you have to do is change the variables in the script header. However for something this basic I didn't worry about creating variables.

For those that are interested here is a basic sample of the shell script for automating an FTP upload:

#!/bin/sh
/usr/bin/ftp -n  <<EOF
open ftp.domain.com
quote user username
quote pass password
prompt off
put /location/filename.html
quit
EOF


This very basic script was failing to login and I couldn't figure out why. The server I was sending the file to is on the Rackspace Cloud sites platform and I was wondering if they were doing something strange with automated ftp transfers. So I decided to test the same script between 2 different servers and it worked fine. The only difference with the new test is I used different usernames and passwords. So I changed the usernames and passwords on the problem server and it worked flawlessly.

This really had me confused, the script now worked, but I needed to find out why it didn't work with the old username and password (which worked fine when done manually.) After some trial and erorr and changing the login credentials back it hit me. The password for the problem account had a $ in it (example: pas$word). I found the culprit of my problems!

In shell scripting (and many other programming languages) you read in assigned variables with a $variablename. So the shell script was trying to enter the letters "p a s" and a variable called $word which didn't exist. So the login was failing (as it should.) If I had assigned a variable at the start of the script I wouldn't have had this issue, or I just need to remember to escape out special characters in scripts like $.

The problem was solved and I now have a reason for the problem in the first place.

Categories:

blog comments powered by Disqus

Featured Photograph

Azaela Closeup

Buy a Print

Recent Entries

Burning Down the House
Talking Heads - Burning Down the House Watch out you might get what you're after Cool baby strange but not…
My 2010 Goals
The start of a new year gives me time to reflect about the coming year and also about the year…
Techie Stuff
One of the reasons I had for converting this website from a photography portfolio website to a blog was to…