Sendmail Hangs When Starting Up or When Using It with PHP

If you notice Sendmail hanging up for many minutes while starting up at boot or while being used such as sending an email from a PHP script, it is probably a DNS lookup problem. Ensure your /etc/hosts file has the appropriate entries for your server that sendmail is running on:

127.0.0.1       localhost localhost.localdomain
192.168.1.80    www.foo.com www
192.168.1.80    www.foo.com.

Replace “www.foo.com” and “www” with your server’s fully qualified domain name and host name respectively. Replace “192.168.1.80” with the IP address of your server. The last entry with the “.” at the end is critical so don’t forget it.

Terminal


	

How to Search for an Exact String With GREP

GREP is one of those simple UNIX programs that you can’t live without if you do any kind of systems administration of an operating system based on UNIX such as Linux or Mac OS X. If you need to search for an exact string and NOT just a substring, all you have to do is specify the “-w” command line switch. For example, say you wanted to search for the string “username” in a text file named “login.php” that contains the following lines:

username = "foo";
groupusername = "myGroupUserName";
defaultusername = "defaultUser";

If you try the command:

grep “username” login.php

all of the lines in the file would be returned since they all contain the substring “username” somewhere in the line.

locahost ~: grep "username" login.php
username = "foo";
groupusername = "myGroupUserName";
defaultusername = "defaultUser";

However if you specify the “-w” command line switch, only the first line will be returned:

localhost ~: grep -w "username" login.php
username = "foo";

Terminal

How to Recursively chmod Directories or Files

Command to recursively chmod only directories:

find . -type d -exec chmod 755 {} \;

How to recursively set the execute bit on every directory:

chmod -R a+X *

The +X flag sets the execute bit on directories only

How to recursively chmod only files:

find . -type f -exec chmod 644 {} \;

How to recursively chmod only PHP files (only for PHP files with the extension .php):

find . -type f -name '*.php' -exec chmod 644 {} \;

You can change the “.php” in the line above to whatever file extension that you want.

How to Determine What Program Is Listening on a Port in OS X or Linux

To determine what daemon or program is listening on a port in Linux or OS X you can use the lsof command. You need to run the command while logged in as root or if your operating system supports sudo like OS X, you can use that.

Command to run in Linux:

lsof -i -nP

Command to run in OS X:

sudo lsof -i -nP

Terminal