Tuesday, November 3, 2009

Linux – disk usage (du) human readable AND sorted by size

— SkyHi @ Tuesday, November 03, 2009
This is quick tip to fix a problem that has always bugged me – When showing disk usage in a human readable form (KB, MB, GB) for each subdirectory using “du -sh *”, how can you properly sort it into size order.

If you just want the solution here it it…

alias duf='du -sk * | sort -n | perl -ne '\''($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}'\' Put it into ~/.bashrc to make it permanent. But if you can spare a minute or two you might get some ideas about how to write those programmatic aliases, in this case using perl. When using the linux “du” command I like to make the file size human readable, so 8709100 becomes 8.4G, This is achieved by doing this: du -sh * Now, the main problem with the K, M and G filesize suffixes is that you can’t sort them. If you try to pipe that through sort by using du -sh * | sort you’ll get something like this 8.4G Desktop 2.6G Documents 12K keys 12M Pictures 536K scripts or if we sort numerically du -sh * | sort -n you’ll get something like this 2.6G Documents 8.4G Desktop 12K keys 12M Pictures 536K scripts Obviously both these commands are not working as we are intending, because the K(ilo) M(ega) G(iga) suffixes mess up “sort”, The solution is a one liner wrapped up into an alias ‘duf’ for ‘disk usage formatted’ alias duf='du -sk * | sort -n | perl -ne '\''($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}'\' When expanded out, formatted and commented the code looks like this

du -sk * | sort -n | //get usage in KBytes and sort
perl -ne ' //we use perl to reformat the filesize in K M & G
($s,$f)=split(m{\t}); //splits the size/filename pair
for (qw(K M G)) { //loops for each size
if($s<1024) { //if s<1024 weve found the correct suffix printf("%.1f",$s); //display the size print "$_\t$f"; //display the filename last //line completed }; $s=$s/1024 //for each sizes suffix divide by 1024 }'


du -h --max-depth=1


This produces the output we intended like this.

12.0KB keys
536.0KB scripts
11.7MB Pictures
2.5GB Documents
8.3GB Desktop

Here some useful additions that are worth adding as an edit to my original post:

1) Purely as a shell script, without the perl overhead - source 'inataysia' reddit
du -sk * | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done

2) As a function, instead of an alias - which allows you to pass paramters to du - source 'fire'
function duf {
du -sk "$@" | sort -n | perl -ne '($s,$f)=split(/\t/,$_,2);for(qw(K M G T)){if($s<1024){$x=($s<10?"%.1f":"%3d");printf("$x$_\t%s",$s,$f);last};$s/=1024}' } Combining together would probably make the best solution so far. function duf { du -sk "$@" | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done } If this has been useful to you, and would like to buy me a coffee (via paypal) please click here. May 13th, 2009 | Tags: Command Line, Computing, Linux, Linux tips | Category: Computing, Linux Command Line Tips | 15 comments 15 comments to Linux – disk usage (du) human readable AND sorted by size * Casper May 14th, 2009 at 8:16 am Thanks for this cool script. One caveat is to watch out to use this in some top-level folder, it can take a very long time to finish. (Wish we had file systems that maintained directory size somehow.) * Twitted by metoikos May 14th, 2009 at 9:42 am [...] This post was Twitted by metoikos – Real-url.org [...] * Curtis May 15th, 2009 at 2:38 am du -s * | sort -n | sed -Ee ’s/^[0-9]+./”/’ -e ’s/$/”/’ | xargs du -sh Perl-less implementation; a little extra effort for filenames with spaces. (Yours doesn’t have to worry about that, obviously.) * Michael Speer May 15th, 2009 at 3:11 am http://www.nabble.com/Human-readable-sort-td23223205.html Never discount simply fixing the underlying problem. * Alex Shinn May 15th, 2009 at 5:04 am That’s always bugged me as well! I’ve made a few changes, though, so that it produces the same formatted output as du -sh. Also, as a function it can take arguments: function duf { du -sk "$@" | sort -n | perl -ne '($s,$f)=split(/\t/,$_,2);for(qw(K M G T)){if($s<1024){$x=($s<10?"%.1f":"%3d");printf("$x$_\t%s",$s,$f);last};$s/=1024}' } * Chris May 15th, 2009 at 5:50 am @casper I don’t. I prefer not to pay an additional cost on every write, to speed up this far-less-frequent case. * Leonid Volnitsky May 15th, 2009 at 6:08 am Latest version of sort (part of coreutils) supports -h (correct sorting of M,k,G suffixes). * fire May 15th, 2009 at 7:02 am I use the following… you see it use ‘du’ two times, but this is not really slower, ’cause the operating system caches. # sorted du -hsc function duhs() { du -s $* | sort -n | cut -f 2- | while read a; do du -sh $a; done } * DVoita May 15th, 2009 at 7:09 am If you modify du -sk * to du -sk * .??* you can see hidden dot files as well. * chris May 15th, 2009 at 8:04 am Thanks to inataysia on reddit for a bash only version du -sk * | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done * Gordon Mohr May 18th, 2009 at 12:11 am Why not promote the ‘human-readability’ step to a standalone utility? Let’s call it ‘hu’ for ‘human units’. Hypothetically, it would convert any whitespace-delimited numbers found on stdin to human-readable units when echoing to stdout. (Optional arguments could limit this conversion to just certain fields or to alternate unit systems.) Then the solution would be: du -sb * | sort -n | hu * Michael Speer May 18th, 2009 at 3:37 pm Sat Jan 20 06:00:09 1996 Jim Meyering (——@na-net.ornl.gov) —snip— * du.c (main): New options –human-readable (-h) and –megabytes (-m). (human_readable): New function. From Larry McVoy (——@sgi.com). Ever since this patch was included in fileutils, system administrators have been frustrated by finding that while they could `du -h` they could not then `sort -h` the output. -h is not posix but is now solidly a part of the gnu coreutils du and ls commands. Including a switch for sort that respects the switch for du was not my invention. It has been argued a number of times on the developers mailing list. Mine was simply the straw which broke the camels back. The additional switch is consistent with the other tools, and merely augments the purpose of sort without creating a differing utility to it. Something of the functionality of `hu` may have been the appropriate fix in ‘96, but since the ‘96 -h switch is long set, adding a corresponding switch to sort seems only too appropriate. To `promote’ -h out of du, df and ls into a separate utility would break scripts of users that depend on it. * Josh May 18th, 2009 at 6:45 pm You can also set the BLOCK_SIZE environment variable to the value human-readable and all the GNU coreutils that report sizes will respect it. * Jason Sares May 19th, 2009 at 6:54 am my solution du -s * 2>/dev/null | sort -n | cut -f2 | xargs du -sh 2>/dev/null
*
Gordon Mohr
May 19th, 2009 at 10:46 pm

I like ‘-h’ too; it doesn’t have to go away for ‘hu’ to also exist and be useful in other contexts, or when people need a sort to precision hidden by ‘-h’ rounding.

Monday, November 2, 2009

How to Disable IPv6 in Fedora and CentOS

— SkyHi @ Monday, November 02, 2009
They say that by disabling IPv6 things get a bit smoother and faster regarding networking. I don’t really know if this is true, but I guess, if you’ve decided to disable this feature, you probably care to do it the Right Way™. As far as I know, trying to disable IPv6 through anaconda during the installation of Fedora or CentOS does not turn off the IPv6 functionality completely, but it just disables it for the configured network interface. This is not actually a problem, but, why should this network layer be enabled system-wide, if you do not use it at all? This small article assists you in disabling IPv6 in the latest Fedora and CentOS releases in an aggressive and unforgiving way.
Check if the module is loaded

IPv6 functionality is being made available to the system by the ipv6 kernel module. To check if this module is currently loaded in your system, issue the following command as root:

lsmod | grep ipv6

If you see ipv6 in its output, then the module is loaded.

Performing this check is absolutely not necessary. It is included in this article for completeness.
Disable IPv6

You can prevent a module from being inserted into the kernel by either blacklisting it or by completely disabling it.

In this case, since you will most probably turn off the IPv6 firewall (ip6tables) as well, it is highly recommended to completely disable the ipv6 module, to avoid any accidental loading of the IPv6 stack without any firewall protection at the same time.
How the module blacklist works

This information about blacklisting a kernel module exists here for educational purposes. It has been mentioned above that for ipv6 it is important to completely disable it.

From the modprobe.conf man page:

Modules can contain their own aliases: usually these are aliases describing the devices they support, such as “pci:123…”. These “internal” aliases can be overridden by normal “alias” keywords, but there are cases where two or more modules both support the same devices, or a module invalidly claims to support a device: the blacklist keyword indicates that all of that particular module’s internal aliases are to be ignored.

So, blacklist indicates that a module’s aliases should be ignored. But, what happens if an application requires to load that specific module or if root uses modprobe to load it on demand? Let’s test it…

To blacklist the module, simply save the following line in a file inside /etc/modprobe.d:

blacklist ipv6

Next, disable any services that use IPv6, eg ip6tables or any IPv6-enabled network interfaces and reboot (mandatory).

After you’ve logged-in again, try, for example, to load the ipv6 module with the modprobe command (as root):

[root@centos]# modprobe -v ipv6
insmod /lib/modules/2.6.18-53.1.14.el5/kernel/net/ipv6/ipv6.ko
[root@centos]# lsmod | grep v6
ipv6 251393 8

The blacklisted module has been loaded. This is what happens if it is needed by a system service, regardless of the fact that it has been blacklisted. In the case of ipv6 this could be a security risk, provided that the ipv6 firewall has been turned off but some network interfaces still use IPv6. So, frankly, it is suggested to read on how to disable the module more aggressively…
Completely disable the ipv6 module

To completely disable IPv6 in your system, all you have to do is save the following line in a file inside /etc/modprobe.d/.

install ipv6 /bin/true

The above line means: whenever the system needs to load the ipv6 kernel module, it is forced to execute the command true instead of actually loading the module. Since /bin/true, does absolutely nothing, the module never gets loaded.

Again, it is required to reboot for the changes to take effect.

It is obvious that this is an aggressive method to disable kernel modules, but it guarantees that the module never gets loaded.

This is the recommended way to disable IPv6.
Other Configuration Tasks

Since the IPv6 functionality has been disabled, you can disable the ip6tables service (IPv6 Firewall). Issue the following command as root:

chkconfig ip6tables off

It is also a good idea, since the ip6tables service has been turned off, to disable any IPv6-related functionality in the network interface configuration. Even if you do not do this, the IPv6 stack will not be initialized because the ipv6 module cannot be loaded. But, generally, you could set the following options to “no” inside your network interface scripts, for example: /etc/sysconfig/network-scripts/ifcfg-eth0

IPV6INIT=no
IPV6_AUTOCONF=no

Finally, In fedora 8 or newer you can safely remove the following option from the /etc/sysconfig/network file, if it exists:

NETWORKING_IPV6=no

Final Thoughts

Using the instructions above, you can completely disable IPv6 in your system. On the other hand, you should understand that IPv6 is not an evil thing… It exists in order to address certain issues. If you ever think about actually trying to configure and use it instead of just disabling it every time you install your Linux operating system, here is a good place to start…
The How to Disable IPv6 in Fedora and CentOS by George Notaras, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Terms and conditions beyond the scope of this license may be available at www.g-loaded.eu.

Reference: http://www.g-loaded.eu/2008/05/12/how-to-disable-ipv6-in-fedora-and-centos/


RedHat / Centos Disable IPv6 Networking

Our policy and network configuration does not requires IPv6 support in RHEL / CentOS / Fedora Linux. How do I prevent the kernel module from loading at boot time and disable IPv6 networking?

You can easily prevent the kernel module from loading by updating the following two files:

1. /etc/modprobe.conf - Kernel driver configuration file.
2. /etc/sysconfig/network - RHEL / CentOS networking configuration file.

/etc/modprobe.conf

Edit /etc/modprobe.conf, enter:
# vi /etc/modprobe.conf
Append the following line:

install ipv6 /bin/true

Save and close the file.
/etc/sysconfig/network

Edit /etc/sysconfig/network, enter:
# vi /etc/sysconfig/network
Update / add as follows:


NETWORKING_IPV6=no
IPV6INIT=no


Save and close the file. Restart networking service
# service network restart
# rmmod ipv6
Alternatively, simple reboot the box:
# reboot
Verify IPv6 is disabled, enter:
# lsmod | grep ipv6
# /sbin/ifconfig

Reference: http://www.cyberciti.biz/faq/redhat-centos-disable-ipv6-networking/



8. How do I disable IPv6?

* Edit /etc/sysconfig/network and set "NETWORKING_IPV6" to "no"
* Add the following to /etc/modprobe.conf :

alias ipv6 off
alias net-pf-10 off

*

Run chkconfig ip6tables off to disable the IPv6 firewall
* Reboot the system

Alternative (which might be easier and works on any release with /etc/modprobe.d):

echo "install ipv6 /bin/true" > /etc/modprobe.d/disable-ipv6

* With the 5.4 update symbol/ipv6 module dependency capabilities have been introduced; therefore, if IPv6 has been previously disabled as above an upgrade to the bonding driver in 5.4 will result in the bonding kernel module failing to load. For the module to load properly use instead:

echo "options ipv6 disable=1" > /etc/modprobe.d/disable-ipv6

Reference: http://wiki.centos.org/FAQ/CentOS5




How do I disable the IPv6 protocol in Red Hat Enterprise Linux?
Release Found: Red Hat Enterprise Linux 4 and later



Red Hat Enterprise Linux 4 and 5 enable Internet Protocol Version 6 (IPv6) by default. However, in certain situations, some users may find it desirable to disable IPv6 support.



Disabling IPv6 Support Red Hat Enterprise Linux 4



If the following line exists in the /etc/modprobe.conf file, remove it:



alias net-pf-10 ipv6



Add the following line to the /etc/modprobe.conf file:



alias net-pf-10 off



Reboot the system to disable IPv6 support.



Re-enabling IPv6 Support Red Hat Enterprise Linux 4



Remove the following line from the /etc/modprobe.conf file.



alias net-pf-10 off



You must reboot the system to activate IPv6 support.


Disabling IPv6 Support Red Hat Enterprise Linux 5



If the following line exists in the /etc/modprobe.conf file, remove it:



alias net-pf-10 ipv6



Add the following line to the /etc/modprobe.conf file:



alias net-pf-10 off



In versions of Red Hat Enterprise Linux before 5.4, add the following line to the /etc/modprobe.conf file:



alias ipv6 off



In Red Hat Enterprise Linux 5.4 and later, add the following line to the /etc/modprobe.conf file:



options ipv6 disable=1



To prevent errors during the network initscript start routine, change the NETWORKING_IPV6 parameter in the /etc/sysconfig/network file to the following:



NETWORKING_IPV6=no



For completeness, it is a good idea to configure the ip6tables service not to start at boot by issuing the following command:



chkconfig ip6tables off



Once both the alias net-pf-10 off and alias ipv6 off lines are present in the /etc/modprobe.conf file and NETWORKING_IPV6=no is set in the /etc/sysconfig/network file, reboot the system to disable IPv6 support.



Re-enabling IPv6 Support Red Hat Enterprise Linux 5



To re-enable IPv6 on Red Hat Enterprise Linux 5 systems, remove the following lines from the /etc/modprobe.conf file:



alias net-pf-10 off

alias ipv6 off



Set the following parameter in the /etc/sysconfig/network file:



NETWORKING_IPV6=yes



Re-enable ipv6tables by issuing the following command:



chkconfig ip6tables on



You must reboot the system to activate IPv6 support.

Reference: http://kbase.redhat.com/faq/docs/DOC-8711

Friday, October 30, 2009

DOS

— SkyHi @ Friday, October 30, 2009
Attacker's ip:

[home@]# netstat -ntu |awk '{print $5}'| cut -d: -f1 | sort | uniq -c |sort -nr

or better
-bash-3.00$ netstat -ntu |awk '{print $5}'| cut -d: -f1 | uniq -c |sort -nr


20 192.168.0..46
7 192.168.0..16
6 64.180.101.157
5 74.37.178.89
4 24.85.255.237
4 192.168.0..236
2 96.54.64.154
2 64.59.144.87
2 64.180.39.28
2 192.168.0..18
1 servers)
1 Address
1 96.49.98.91
1 79.21.99.6
1 70.79.180.109
1 67.218.116.130
1 67.195.112.44
1 67.195.111.152
1 67.174.99.48
1 24.78.246.41
1 216.104.15.130
1 205.189.8.130
1 192.168.0..235
1 174.6.25.230
1 173.66.78.212

OR
Ex. ::ffff:67.195.37.154:59987
netstat -ntu | awk '{print $5}'| cut -d: -f4 | sort | uniq -c |sort -nr

Victim's ip:

[home@]# netstat -ntu |awk '{print $4}'| cut -d: -f1 | sort | uniq -c |sort -nr
20 192.168.0..46
7 192.168.0..16
6 64.180.101.157
5 74.37.178.89
4 24.85.255.237
4 192.168.0..236
2 96.54.64.154
2 64.59.144.87
2 64.180.39.28
2 192.168.0..18
1 servers)
1 Address
1 96.49.98.91
1 79.21.99.6
1 70.79.180.109
1 67.218.116.130
1 67.195.112.44
1 67.195.111.152
1 67.174.99.48
1 24.78.246.41
1 216.104.15.130
1 205.189.8.130
1 192.168.0..235
1 174.6.25.230
1 173.66.78.212

Monday, October 19, 2009

Disable Recent Shares in Network Places

— SkyHi @ Monday, October 19, 2009
Submitted by atomicrabbit

This restriction stops remote shared folders from being added to Network Places whenever you open a document in the shared folder.

Disabling this option can speed up network browsing as well as keep the My Network Places folder clean.

0 = track shares
1 = disable tracking
» Example Registry Tweak

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoRecentDocsNetHood"=dword:00000001

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoRecentDocsNetHood"=dword:00000001

Reference: http://unattended.msfn.org/unattended.xp/view/registry/90/SESSID=05901bb54208da41953351329d097d80/



Disable NetBios (Windows) And Increase Security - Increase your computer security
Disable NetBIOS

Increase your security

If NetBIOS is enabled
Your Files and Folders , Work Group-name , Computer name , Loging- name will be shared in Internet

in Windows 2000

1- open Windows Explorer
2- Right click on My Network places and select properties
3- Click Internet protocol TCP/IP and select properties
4- Click on Advanced and then WINS
5- Select Disable NetBIOS over TCP/IP and click ok
6- Restart your computer

If Windows displays “This connection has an empty … " message, ignore it

Reference: http://www.astahost.com/info.php/Disable-Netbios-Windows-Increase-Security_t8863.html


Disable automatic share and print discovery in Windows XP
Windows XP automatically searches the network for shares and printers upon connecting to the network. This is probably useful in a SOHO or home network but not the enterprise. To disable XP automatic discovery:

* In Explorer, click Tools
* Click Folder Options
* Click the View tab,
* Uncheck Automatically Search for Network Folders and Printers in Advanced settings list.

It is important to disable this setting in Windows XP because it is the basis of a seriouse security flaw in XP. When you click My Network Places, your logon password may be transmitted automatically to numerous unspecified computers on the LAN. Windows XP tries to acquire the shared resources list of all computers on the LAN. At that time, the users local logon password is used when the password for the shared resource is not known. Your PC transmits the LMhash version of you password.

If there are NT4.0 or any other pre-Windows 2000 PCs on the LAN, XP will transmit your password to the pre-Windows 2000 PCs during its share and print search. It transmits the LM hash which is significantly weaker than XP or Windows 2000 hashes. In order to protect the LM hash, XP has a registry value HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\NoLMHash which if set to 1 will prevent XP or Windows 2000 from generating the LM hash. pwdump will not be able to acquire the LM hash, which is a good thing.

Saddly, NoLMHash does not affect LM authentication. Even if NoLMHash has been set, XP will still transmit the LM hash to a NT4.0 machine when My Network Places is clicked.

http://www.windowsnetworking.com/nt/xp/atips/atips23.shtml

Friday, October 16, 2009

Find the largest top 10 files and directories

— SkyHi @ Friday, October 16, 2009
List files newer than 1 days
#find . -mtime -1 -ls


find files older than 1 year and get the total disk usage of those files
#nice find / -type f -mtime +365 |xargs du -hs


http://www.computing.net/answers/unix/list-files-newer-than-10-days/4440.html

Sometime it is necessary to find out what file(s) or directories is eating up all disk space. Further it may be necessary to find out it at particular location such as /tmp or /var or /home etc.
There is no simple command available to find out the largest files/directories on a Linux/UNIX/BSD filesystem. However, combination of following three commands (using pipes) you can easily find out list of largest files:
  • du : Estimate file space usage
  • sort : Sort lines of text files or given input data
  • head : Output the first part of files i.e. to display first 10 largest file
Here is what you need to type at shell prompt to find out top 10 largest file/directories is taking up the most space in a /var directory/file system:
# du -a /var | sort -n -r | head -n 10

Output:
1008372 /var
313236  /var/www
253964  /var/log
192544  /var/lib
152628  /var/spool
152508  /var/spool/squid
136524  /var/spool/squid/00
95736   /var/log/mrtg.log
74688   /var/log/squid
62544   /var/cache


If you want more human readable output try:
# du -ks /var | sort -n -r | head -n 10
Where,
  • -a : Include all files, not just directories (du command)
  • -h : Human readable format
  • -n : Numeric sort (sort command)
  • -r : Reverse the result of comparisons (sort command)
  • -n 10 : Display 10 largest file. If you want 20 largest file replace 10 with 20. (head command)
Updated for accuracy!


REFERENCE
http://www.cyberciti.biz/faq/how-do-i-find-the-largest-filesdirectories-on-a-linuxunixbsd-filesystem/

Tuesday, October 13, 2009

cgi 500 Internal Server Error

— SkyHi @ Tuesday, October 13, 2009
..and how to fix it.

When running a Perl CGI script, you may see the "Internal Server Error" message in your browser. The message will usually also say something like "please check the server's error-log for more information." You should do that -- the message printed to the error log will often tell you exactly what the problem is. The Apache error log, for example, is often located at /var/log/apache/error_log or /var/log/apache2/error_log (or sometimes "error.log").

If you don't have access to the error log, the next simplest thing to do is to make a copy of the script, then open the original and delete all of its contents, and add just these 3 lines to the file:

#!/usr/bin/perl
print "Content-type: text/plain\n\n";
print "testing...\n";

(Note: if the server is a Windows system, then replace the first line above with either #!perl or #!c:\path\to\perl.exe.)

Now try to access the page in your browser again. If it works (you see "testing..." as its output) then you know that your server is at least configured properly for running Perl CGI scripts. If it doesn't work, then that may mean the problem is in the server configuration, rather than with your CGI script. (For example, are you sure you actually have Perl installed? Virtually all UNIX/Linux/OS X servers do, but Windows servers usually need to have it installed manually, from a package like ActivePerl.)

Assuming your server is configured properly for running CGI scripts, your problem may be one of these common causes for the Internal Server Error:
Problems outside the script:

1. Directory permissions: your cgi-bin directory should be chmodded as 0755, not 0777. Similarly if your script is at .../cgi-bin/foo/bar.cgi, the foo directory must not be world-writable (0777). This is because many servers will refuse to execute CGI scripts within world-writable directories, as a security precaution.
2. File permissions: your CGI script itself must also be 0755 and not 0777, for the same reasons.
3. Transfer modes: if you are using FTP to transfer the CGI script to your server, then your FTP client is probably set to AUTO transfer mode; that is, it will try to figure out whether to use BINARY or ASCII mode without asking you. But depending on whether your CGI script came from a Windows or UNIX system, and whether it's going to a Windows or UNIX system, you may need to manually set your FTP client to use either ASCII or BINARY mode before transferring your CGI script. Try one and then the other.
4. Line endings: the cause of the transfer-mode problem is actually another problem in itself: different types of Operating Systems (namely, Windows vs. UNIX/Linux/everything) use different character codes to represent line-endings. If your server is a UNIX server, but you're editing your CGI script on a Windows computer with a text-editor that doesn't use UNIX-style line-endings, it'll cause problems. Applications like GoLive and Dreamweaver sometimes get this wrong. Even built-in editors can't agree: WordPad (not Word) seems to get it right while Notepad messes it up. So try opening & saving your CGI script in a different text editor and uploading it to the server again.

Problems within the script:

1. The shebang line: the first line of a CGI script must contain the path to the Perl binary on the server. On most UNIX servers this is just #!/usr/bin/perl or sometimes #!/usr/local/bin/perl and you can always run the command "which perl" to find out for sure. On Windows servers, you can sometimes get away with just using #!perl but you may need to specify the full path like #!c:\path\to\perl.exe.
2. Actual script errors: it's always possible that there's simply an error in the Perl code itself. If you're having trouble with a script you purchased from Encodable Industries, this is unlikely since many other people have bought the same exact script and are running it just fine.

Related Problems

1. Another common problem with CGI scripts is the premature end of script headers error.


Reference: http://encodable.com/internal_server_error/

.htaccess mod_rewrite to direct non-www to www

— SkyHi @ Tuesday, October 13, 2009
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^dreamincode.(.*)
RewriteRule ^(.*)$ http://www.dreamincode.net/$1 [R=301,L]

Reference: http://www.dreamincode.net/code/snippet1126.htm