Debugging shell script is a bit difficult. You will always find yourself putting lots of “echo” or “print” statement throughout the script to find where it is going wrong. The drawback of such effort are
1) Spending lots of time in finding issue in those echo output.
2) If you miss printing values for certain variable, you will need to write echo statement which will print the values and re-execute the program.
3) Tapping conditional statement would be difficult to trace with print statement alone.
One way of debugging shell script to enable options while executing script and tracing down the output statement for errors. For example, consider the following script ( lets call this script as test.ksh )
1
2
3
4
5
6
| #!/bin/ksh
x="testValue";
while [[ "$x" != "" ]]; do
echo "X is : $x ";
x="";
done |
Executing the following script would give you the result
However if you execute the script with -x option as follows, you will notice every line from script getting printed on standard output which will have variable replaced with the values.
ksh -x test.ksh
2 x=testValue
3 [[ testValue != ]]
4 echo X is : testValue
X is : testValue
5 x=
5 [[ != ]]
You would easily know by looking into such output how the variable x in script is changing the values and if there is any issue in script, you can track it down. This shell feature definitely helps in finding issue faster ( atleast as compared to putting lots of “echo” statement ).
The other option which can help in shell script debugging would be “-n”. From kornshell doc,
“You should always run ksh -n on each script you write. The -n option will check for syntax errors on paths that might not even be checked when you run the script. It also produces a number of warning messages.”
Other way of debugging korn shell script is to use kshdb ( korn shell debugger ). I have not used it enough till date. See kshdb manual for more information on how to enable and debug script.
I was trying to reorganize my unix environment for different work. For example, I do not need oracle environment configuration in a machine where I’ll be using informix database and hence I would need informix related configuration only. For that purpose, I was modifying script to prompt a menu whenever I login with available configuration. I could input my choice as a character and corresponding environment will be loaded.
For example, If my input is “1″, config variables in file 1 will be loaded in shell.
While doing so, I realized, I may need related multiple environment configuration in one shell and hence I should be able to input multiple characters as string and corresponding environment variables will be loaded. My assumption was to read all characters in string and split them in array. Finally loop through the array and load all required variable in shell.
For example, the following shell script splits the string variable strValue using whitespace as delimiter and store them into charArray.
$ export IFS=" ";
$ strValue="1 2 3 4 5";
$ set -A charArray $strValue
$ echo "First Element: ${charArray[0]}"
First Element: 1
My idea was to make IFS make empty string and perform the same thing to split string into character array and hence the code for the same would be
$ export IFS="";
$ strValue="12345";
$ set -A charArray $strValue
But when I tried to iterate through the array as
$ echo "First Element: ${charArray[0]}"
First Element: 12345
I was so wrong! Making IFS empty string does not split the string as character wise into array. But why ? I tried to find an answer but !
I hope you are not using IE6 anymore and hence you do not have to read on. Skip this post please!
Oh! You are still reading. Well for my work, I had to test our webapp in IE6 as well. While doing so, I noticed that IE6 was extremely slow ( Okay! I am not comparing with firefox/safari. only with IE7 ). I started to wonder about it until I came across MS hotfix for IE6 ( http://support.microsoft.com/kb/942840 ). After updating IE6 with this hotfix, IE6 was comparable to IE7 ( and infact I found it faster. Again, not comparing with firefox ).
So if you still using IE6, you may consider this hotfix for faster IE6!
Infact why are using IE6? Go on, upgrade! get IE8 or firefox…
Yesterday when I tried to run Apache web server in my system, it failed to stop. All I could get was an alert message from Apache Monitor was “Requested operation has failed”. No description, No error code, absolutely vague error message.
I tried running apache directly from the installation location and it threw quite descriptive error.

Duh! Looks like apache server failed to get ownership for port 80. But I had not installed any other web server, so which application is using port 80 ? Here is what I did to find out
1) Execute netstat -na -o command ( netstat guide )and search for port 80. The last column in result would indicate the process id for the application which is blocking the port
2) Execute tasklist with find command and see which application is that

Oh! As you can figure out from screenshots, skype was using port 80. So if you are facing similar kind of problem, you need to configure skype first .
Launch Skype. Click on Tools -> Options -> Advanced -> Connection. You would notice a checkbox for using port 80 and 443 as alternatives for incoming connections. Uncheck it, save and restart skype.

Apache did start after configuring skype for me. This is just one of the case why apache throws up such error which I faced.
There could be scenario where your firewall configuration is blocking apache or you configuration file is corrupted.
Alternatively, you could configure apache to listen to other port instead of port80. Search for Listen in httpd.conf and replace port ( do not use standard ports though! ).