Archive for » October, 2008 «

Sunday, October 12th, 2008 | Author: Angelo

Hello,

Change default text editor on linux server.

A. How to find default text editor of linux machine ? — >> You can determine default editor of linux machine from variable EDITOR.

Following command will show default text editor.
root@server [~]#echo $EDITOR
pico

This means default text editor of your linux machine is pico if you want to change it temporary to vi then simply execute following command.

root@server [~]#EDITOR=vi
In case, you want to change default text editor permanently to emacs then edit /root/.bashrc at the bottom of file add line.
export EDITOR=emacs

To, verify is it changed permanently or not, simply logout and login again and execute command.

root@server [~]#echo $EDITOR
emacs

EDITOR variable contains all capital letter because it is system variable. You can find all system variables and it’s value by command env .

root@server [~]#env
It will show all environment variables (system variables).

Sunday, October 12th, 2008 | Author: Angelo

Disable directory listings using .htaccess.

If you want to disable directory listing for any folder then simply create one file as .htaccess in that directory & insert rule IndexIgnore * in that file.

IndexIgnore * means directory will not list any file or folder. If you want to disable listing of .jpg files only then rule would be IndexIgnore *.jpg with this rule directory will list all files and folders excluding files with extension .jpg.

Thursday, October 09th, 2008 | Author: Angelo

Bash shell is command language interpreter which read commands from the standard input or from a file and executes it. Shell scripting is useful tool when someone need to run multiple commands on shell repeatedly. In simple words shell scripting is defining all commands with or without conditions in a file and execute the same file as command.

Sample shell script with name bashscript is given to generate message “Welcome to shell scripting world.”

A. Edit a file using vi editor and add following lines in it.

[Linux server]#vi bashscript

!#/bin/bash
echo "Hi, This is my first shell script"

B. Make the script executable.

[Linux server]#chmod u+x bashscript
Or
[Linux server]#chmod 700 bashscript

C. Executing shell script.

[Linux server]#./bashscript

How to execute shell script as command ?
Just upload bashscript in any directory defined in the environment variable PATH. You can check directories defined in environment variable PATH using command.

[Linux server]#echo $PATH

Now on shell type script name on hash prompt and hit the enter. And you have execute shell script as command.
[Linux server]#bashscript

Script is executed as command.

If you have any question or need any shell script you can query the same as comment for this post. I will update your query or shell script in comment or will write post for the same asap.

Category: shell  | Tags: , , ,  | 2 Comments
Wednesday, October 08th, 2008 | Author: Angelo

Hello,

Below is command to find out number of connections from each ip to server using netstat , sort, uniq, awk.

netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

Here is description of Grep used in this command :: Grep is used for sorting lines which are matching for defined pattern but if you want to sort such lines which are matching two or more different pattern then simply define all patterns in single quote and separate them using \| .

Tuesday, October 07th, 2008 | Author: Angelo

Here is example of rsync command which is used to to delete all files from receiver server which are not exist on sender server.

rsync -e 'ssh -p 4000' -av --delete --progress ./path-to-sender-directory ip-of-remote-server:/path-of-receiver-directory/

Below is description of all parameters used in this command. Rsync stands for remote synchronization, -e to specify remote shell here remote shell we have used is ssh (secure shell running on port 4000), 'ssh -p 4000' consider secure shell ssh is configured on port 4000 on remote server, -a (stands for rpogDtH) & -v for verbose if you are using this command in script then you don’t need to define v, –delete to delete files that does not exist on sender.

./path-to-sender-directory path to sender directory, path to receiver directory username@ip-of-remote-server:/path-of-receiver-directory/ . Also you can use –progress it will show you progress during transfer(don’t use this parameter if you are using this command in shell script).

Also you can use –delete-after instead of –delete so files will be deleted from receiver after transfer not before but it would be better to use –delete because –delete does file deletions on the receiving side before transferring files to try to ensure that there is sufficient space on the receiving filesystem.

In addition there is one more option you can use –delete-excluded this will delete excluded files on receiver, this tells rsync to also delete any files on the receiving side that are excluded (In short you can use this parameter instead of –delete & –excluded).

Monday, October 06th, 2008 | Author: Angelo

Hello,

cPanel tomcat shows directory listing when someone access their site on tomcat port 8080. It is not possible to disable directory listing via .htaccess although tomcat is running on apache port 80. You can disable it on tomcat server by making following changes to web.xml file.

Edit web.xml located in tomcat conf directory and search for line <param-name>listings</param-name> below this line you will find one more line as <param-value>true</param-value> change the value true to false and restart tomcat service and you have disabled directory listing for your tomcat server.

Saturday, October 04th, 2008 | Author: Angelo

Hello,

While starting apache service on cPanel server if you are getting as given below.

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80 or 443
no listening sockets available, shutting down
Unable to open logs

Then it is because httpd is stopped but http port 80 or 443 are still engaged with other service such as exim or mysql. In such case you need to execute following command to find with which service apache port is engaged.
netstat -nap | grep 0.0.0.0:80 or netstat -nap | grep 0.0.0.0:443

For example :: In output if you found exim ( tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 789/exim)
To fix this issue you need to simply restart the exim service on server .

Thursday, October 02nd, 2008 | Author: Angelo

Using mod_layout you can create a single look for your site by placing information at both the beginning and the end of a document (header and footer). It is useful for adding banners at the top or end of all web pages. Also if wish you can insert layouts in documents at any place dynamically.

Below are the steps to install mod_layout on your cPanel server.

Download tar file for installtion

A. wget http://www.tangent.org/download/mod_layout-3.2.1.tar.gz
B. tar xvfz mod_layout-3.2.tar.gz
C. cd mod_layout-3.2
D. vi Makefile
and find following
# the used tools
APXS=apxs
APACHECTL=apachectl
CC=`apxs -q CC`
INC=-I`apxs -q INCLUDEDIR` `$(APXS) -q CFLAGS` #-DLAYOUT_FILEOWNER_NAME
LD_SHLIB=`apxs -q LDFLAGS_SHLIB`

Replace the values with the following details :

# the used tools
APXS=/usr/local/apache/bin/apxs
APACHECTL=apachectl
CC=`/usr/local/apache/bin/apxs -q CC`
INC=-I`/usr/local/apache/bin/apxs -q INCLUDEDIR` `$(APXS) -q CFLAGS` #-DLAYOUT_FILEOWNER_NAME
LD_SHLIB=`/usr/local/apache/bin/apxs -q LDFLAGS_SHLIB`
save the file Makefile and then

E. make
F. make install
G. edit httpd.conf
And added LayoutHeader and LayoutFooter Directive as below.

<Virtualhost www.domainname.com>
LayoutHeader “<P> This is the beginning of things<P>”
LayoutFooter “<P> This is the tail end of things<P>”
</virtualhost>

You are done….

Thursday, October 02nd, 2008 | Author: Angelo

Below is command to find out ports which are in use using netstat & cut.

netstat -na | grep 'tcp\|udp' | awk '{print $4}' | cut -d: -f2 | sort | uniq -c | awk '{print $2}'

Below is description of each commands :: Netstat command is used to check all incoming and outgoing connections on linux server. Using Grep command you can sort lines which are matching pattern you defined. AWk is very important command generally used for scanning pattern and process it. It is powerful tool for shell scripting. Sort is used to sort output and sort -n is for sorting output in numeric order. Uniq -c this help to get uniq output by deleting duplicate lines from it.

Category: exim, Linux Commands  | 19 Comments
Thursday, October 02nd, 2008 | Author: Angelo

Hello,

Below is command to find out number of connections to each port using netstat, cut, awk ,uniq.

netstat -na | grep 'tcp\|udp' | awk '{print $4}' | cut -d: -f2 | sort | uniq -c | awk '{print $2}'

Here, is description for this command so many times you may face trouble because of dos attack in such case you need to find port number (service) on which dos attack is going on above command will help you to search number of connections to each port which is in use.