Archive for February, 2010

IIS 6 performance

February 22nd, 2010

Performance Tuning (IIS 6.0)

Web server administrators often monitor their Web servers to create a performance baseline. A performance baseline is a collection of data that indicates how the servers are performing when everything is running smoothly. Before making changes to their servers in a production environment (for example,. rolling out a new version of a Web application or hardware changes) administrators tune their servers in a test environment to achieve the established performance baseline. By tuning their servers in this way, they maximize throughput and minimize Web application response times, which create a better experience for clients accessing their Web servers.

Using HTTP Compression (IIS 6.0)

To more efficiently use available bandwidth, enable IIS HTTP compression. HTTP compression provides faster transmission time between compression-enabled browsers and IIS, regardless of whether your content is served from local storage or a UNC resource. You can compress static files and application response files. Compressing application response files is usually called dynamic compression.

This section includes the following information:

Enabling HTTP Compression (IIS 6.0)

You can enable HTTP compression server-wide or on a specific directory. HTTP compression improves bandwidth utilization and speeds up Web site performance. In addition, you can compress static or dynamic responses.

Important

You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run IIS Manager as an administrator. At a command prompt, type runas /user:Administrative_AccountName“mmc %systemroot%\system32\inetsrv\iis.msc”.

Procedures

To enable global HTTP compression by using IIS Manager

1.

In IIS Manager, double-click the local computer, right-click the Web Sites folder, and then click Properties.

2.

Click theService tab, and in the HTTP compression section, select the Compress application files check box to enable compression for dynamic files.

3.

Select the Compress static files check box to enable compression for static files.

4.

In the Temporary directory box, type the path to a local directory or click Browse to locate a directory. Once a static file is compressed, it is cached in this temporary directory until it expires, or the content changes. The directory must be on the local drive of an NTFS–formatted partition. The directory cannot be compressed or shared, and the access control lists (ACLs) for the directory must include Full Control access to the identity of the application pool or to the IIS_WPG group.

5.

Under Maximum temporary directory size, click a folder size option. If you specify a maximum size under Limited to (in megabytes) (the default setting is 95 MB), then when the limit is reached, IIS automatically cleans up the temporary directory by applying the “least recently used” rule.

6.

Click Apply, and then click OK.

Important

You must be a member of the Administrators group on the local computer to run scripts and executables. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run your script or executable as an administrator. At a command prompt, type runas /profile /user:MyComputer\Administratorcmd to open a command window with administrator rights and then type cscript.exeScriptName (include the script’s full path and any parameters).

To enable global HTTP compression by using Adsutil.vbs

1.

Open a command prompt.

2.

To enable dynamic compression, type the following at the command prompt and then press ENTER:cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoDynamicCompression true

3.

To enable static compression, type the following at the command prompt and then press ENTER:cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoStaticCompression true

To enable HTTP Compression for Individual Sites and Site Elements

1.

Disable global static compression by executing the following command at a command prompt:adsutil set w3svc/filters/compression/parameters/HcDoStaticCompression false

2.

Enable static compression at this directory by executing the following command at a command prompt:adsutil set w3svc/1/root/Home/StyleSheets/DoStaticCompression true

To disable static compression for only a single directory, first enable global static compression (if it is disabled) and then disable static compression at that directory. For example, to enable static compression for a directory at http://www.contoso.com/Home/StyleSheets, perform the following steps:

1.

Disable global static compression by executing the following command at a command prompt:adsutil set w3svc/filters/compression/parameters/HcDoStaticCompression true

2.

Enable static compression at this directory by executing the following command at a command prompt:adsutil set w3svc/1/root/Home/StyleSheets/DoStaticCompression false

Related Information

For a detailed discussion of how HTTP compression works, how to test compression, and detailed compression configuration options, see Using HTTP Compression for Faster Downloads.
For more information about improving the performance of IIS network resources using related features like bandwidth throttling and connection timeouts, see Administering Network Resources.
For information on configuring the types of files IIS compresses server-wide, see Customizing the File Types IIS Compresses.

Enabling HTTP Keep-Alives (IIS 6.0)

Most Web browsers request that the server keep the client connection open while the server sends multiple elements (.htm files and .gif or .jpeg files) to the client. Keeping the client connection open in this way is referred to as an HTTP Keep-Alive. Keep-Alive is an HTTP specification that improves server performance. HTTP Keep-Alives are enabled by default.

Important

You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run IIS Manager as an administrator. At a command prompt, type runas /user:Administrative_AccountName “mmc %systemroot%\system32\inetsrv\iis.msc”.

Procedures

To enable HTTP Keep-Alives

1.

In IIS Manager, expand the local computer, expand the Web Sites folder, right-click the Web site, and click Properties.

2.

On the Web Site tab, in the Connections section, click the Enable HTTP Keep-Alives check box.

3.

Click Apply, and then click OK.

Related Information

For information about HTTP Keep-Alives, including security requirements and how disabling keep-alives can impact the server, see Enabling HTTP Keep-Alives to Keep Connections Open.
For more information about improving the performance of IIS network resources using related features like HTTP Compression, bandwidth throttling, and connection limits, see Administering Network Resources.

Limiting Connections (IIS 6.0)

Connection limits restrict the number of simultaneous client connections to your Web sites and your Web server. Limiting connections conserves memory and protects against malicious attacks designed to overload your Web server with thousands of client requests.

Important

You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run IIS Manager as an administrator. At a command prompt, type runas /user:Administrative_AccountName “mmc %systemroot%\system32\inetsrv\iis.msc”.

Procedures

To set a global WWW or FTP service connection limit

1.

In IIS Manager, expand the local computer, right-click the Web Sites or FTP Sites folder, and then click Properties.

2.

Click the FTP Site tab to limit connections on the FTP service, or click the Performance tab to limit connections on the WWW service.

3.

Click the Connections limited to option, and in the box next to it, type the maximum number of simultaneous connections you want to allow on your Web or FTP service.

4.

Click Apply, and then click OK.

To set a Web or FTP site connection limit

1.

In IIS Manager, expand the local computer, expand the Web Sites or FTP Sites folder, right-click the Web or FTP site on which you want to set the connections limit, and click Properties.

2.

Click the FTP Site tab to limit connections on the FTP site, or click the Performance tab to limit connections on the Web site.

3.

Click the Connections limited to option, and in the box next to it, type the maximum number of simultaneous connections you want to allow on your Web or FTP site.

4.

Click Apply, and then click OK.

Related Information

For more detailed information about IIS connection limits, including the security ramifications of selecting the Unlimited option, see Limiting Connections to Manage Resources.
For more information about improving the performance of IIS network resources using related features like HTTP Compression and bandwidth throttling, see Administering Network Resources.

Setting Connection Timeouts (IIS 6.0)

Connection time-outs help reduce the loss of processing resources consumed by idle connections. When you enable connection time-outs, IIS enforces the time-outs at the connection level.

Important

You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run IIS Manager as an administrator. At a command prompt, type runas /user:Administrative_AccountName “mmc %systemroot%\system32\inetsrv\iis.msc”.

Procedures

To set a global WWW or FTP service connection time-out value

1.

In IIS Manager, expand the local computer, right-click the Web Sites or FTP Sites folder, and click Properties.

2.

On the Web Site or FTP Site tab, in the Connection timeout box, type the maximum number of seconds that IIS should maintain an idle connection before resetting the connection.

3.

For the WWW service, verify that the Enable HTTP Keep-Alives box is selected. For more information, see Enabling HTTP Keep-Alives.

4.

Click Apply, and then click OK.

To set a connection time-out value for a specific Web or FTP site

1.

In IIS Manager, expand the local computer, expand the Web Sites or FTP Sites folder, right-click a Web or FTP site, and click Properties.

2.

On the Web Site or FTP Site tab, in the Connection timeout box, type the maximum number of seconds that IIS should maintain an idle connection before resetting the connection.

3.

For the WWW service, verify that the Enable HTTP Keep-Alives box is selected. For more information, see Enabling HTTP Keep-Alives.

4.

Click Apply, and then click OK.

Related Information

For more information about connection timeouts, including which counters to use to monitor connection timeouts, see Setting Connection Timeouts to Save Resources.
For more information about improving the performance of IIS network resources using related features like bandwidth throttling, HTTP Compression, and connection limits, see Administering Network Resources.
For information about setting CGI application timeouts, see Configuring CGI Application Timeouts.

Throttling Bandwidth (IIS 6.0)

If the network or Internet connection used by your Web server is also used by other services such as e-mail or news, you may want to limit the bandwidth used by your Web server so it is available for those other services. If your Web server hosts more than one Web site, you can individually throttle the bandwidth used by each site.

This section includes the following information:

Enabling Packet Scheduler: Describes how to enable Packet Scheduler when configuring a site to use bandwidth throttling without using IIS Manager.
Enabling Bandwidth Throttling: Describes how to enable bandwidth throttling globally for the WWW service and for individual Web sites.
Disabling Bandwidth Throttling: Describes how to disable bandwidth throttling for individual Web sites.

Related Information

For more information about when and where to use bandwidth throttling, see Throttling Bandwidth to Manage Service Availability.
For more information about improving the performance of IIS network resources using related features like HTTP Compression and connection limits, see Administering Network Resources.

Enabling CPU Monitoring in IIS 6.0 (IIS 6.0)

The CPU monitoring feature monitors and automatically shuts down worker processes that consume large amounts of CPU time. CPU monitoring is enabled for individual application pools.

Before enabling CPU monitoring, take note of the following:

IIS must be operating in Worker Worker Process Isolation Mode.
CPU monitoring is available only for application pools.
CPU monitoring does not apply to CGI applications.

Important You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run IIS Manager as an administrator. At a command prompt, type runas /user:Administrative_AccountName “mmc %systemroot%\system32\inetsrv\iis.msc”.

Enabling CPU Monitoring by Using IIS Manager

When you enable CPU monitoring by using IIS Manager, IIS allows, by default, a maximum CPU use of 50 percent. To change the default value, follow this procedure.

To enable CPU monitoring

1.

In IIS Manager, expand the local computer, expand the Application Pools folder, right-click the application pool for which you want to enable CPU accounting, and click Properties.

2.

Click the Performance tab, and select the Enable CPU monitoring check box.

3.

In the Maximum CPU use box, click the up and down arrows to set the maximum percentage of the CPU the application pool should use. If the application pool uses more than the designated maximum, IIS generates an error in the Windows Events log.

4.

In the Refresh CPU usage numbers (in minutes) box, click the up and down arrows to set the refresh rate.

5.

In the Action performed when CPU usage exceeds maximum CPU use list box, click the appropriate action for the designated application pool.
To have IIS write an event to the system log when the application pool reaches the maximum CPU usage, without shutting the application pool down, click No Action.
To shut down the application pool in addition to logging an event in the system log, click Shutdown.By default, No Action is selected.
ImportantShutting down the application pool shuts down all worker processes that serve that application pool.

6.

Click Apply, and then click OK.

Top of page

Enabling CPU Monitoring from the Command Line

Enabling CPU monitoring from the command line can take as many as three steps:

Set the CPULimit metabase property, which limits the worker processes in a specified application pool to a percentage of CPU time.
Set the CPUResetInterval metabase property, which specifies the time interval for CPU monitoring.
Set the CPUAction metabase property, which specifies the type of action you want IIS to take, such as write to the event log or shut down worker processes that exceed the CPU limit.

Set the CPU Limit

TheCPULimitproperty configures the maximum percentage of CPU time that the worker processes in an application pool are allowed to consume over the period of time set by the CPUResetInterval property. If the limit set by the CPULimit property is exceeded, an event is written to the event log and an optional set of events can be triggered as determined by the CPUAction property. Setting the value of the CPULimit property to zero disables CPU monitoring.

To start CPU monitoring for an application pool, set the CPULimit property to a value greater than zero. To calculate the value to set, determine the maximum percentage of CPU time that you want the worker processes in an application pool to use — for example, 50 percent (which is the default value). Next multiply that percentage by 1,000 (50  1,000 = 50,000). Hence, to limit CPU use to 50 percent, set a value of 50000 for the CPU limit.

To set the CPU limit for CPU monitoring by using Adsutil.vbs

1.

In the Run dialog box, type cmd, and then click OK.

2.

At the command prompt, type:cscript %Systemroot%\Inetpub\AdminScripts\adsutil.vbs set W3SVC/AppPools/ApplicationPoolName/CPULimit nReplace n with the maximum percentage of CPU use to allow for the application pool in 1/1,000ths of a percentage.

Set the CPU Reset Interval

After turning on CPU monitoring for the application, use Adsutil.vbs to set a value for the CPUResetInterval property, which specifies the reset period (in minutes) for CPU monitoring and throttling limits on the application pool. When the number of minutes elapsed since the last CPU monitoring reset equals the number specified by this property, IIS resets the CPU timers for both the logging and limit intervals. The default value is five minutes. Setting the value of this property to zero disables CPU monitoring.

Important

The value of the CpuResetInterval property must be greater than the time between logging operations; otherwise, IIS resets counters before logging has occurred, and CPU monitoring does not occur.

To set the CPU monitoring reset interval by using Adsutil.vbs

1.

In the Run dialog box, type cmd, and then click OK.

2.

At the command prompt, type:cscript %SystemDrive%\Inetpub\AdminScripts\adsutil.vbs set W3SVC/AppPools/ApplicationPoolName/CPUResetInterval nReplace n with the number of minutes for the reset interval. To disable CPU monitoring, type 0.

Set the CPU Action

Finally, set the CPUAction property, which configures the actions that IIS takes when Microsoft® Windows NT® job objects run. Only one Windows NT job object exists per application pool; therefore, you must configure the CPUAction property separately for each application pool. If you do not set the CPUAction metabase property, IIS assigns the default value, which is zero (event logging only).

To set the CPUAction value by using Adsutil.vbs

1.

In the Run dialog box, type cmd, and then click OK.

2.

At a command prompt, type:cscript %SystemDrive%\Inetpub\AdminScripts\adsutil.vbs set W3SVC/AppPools/ApplicationPoolName/CPUAction ActionValueReplace ActionValue with the appropriate value: 0 logs an error without shutting down the process; 1 logs an error and shuts down the process.

For more information about setting the CPU action, see the CPULimit Metabase Property, the CPUResetInterval Metabase Property, and theCPUAction Metabase Property.

Related Information

For more information about CPU Monitoring, including explanations of the corresponding metabase properties and options for advanced CPU monitoring with Windows System Resource Manager, see Enabling CPU Monitoring.
For information about related features that help manage and conserve resources when IIS is running in Worker Process Isolation Mode, see Managing Resources in Worker Process Isolation Mode.

Configuring Application Pool Queue-Length Limits (IIS 6.0)

Application pool queue-length limits prevent large numbers of requests from queuing up and overloading your server. When application pool queue-length limits are enabled, IIS monitors the number of requests for a designated application pool queue before queuing a new request. If adding the new request to the queue exceeds the queue size, the server rejects the request and sends an uncustomizable 503-error response to the client.

Important

You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run IIS Manager as an administrator. At a command prompt, type runas /user:Administrative_AccountName “mmc %systemroot%\system32\inetsrv\iis.msc”.

Procedures

To change an application pool queue-length limit using IIS Manager

1.

In IIS Manager, expand the local computer, expand the Application Pools folder, right-click the application, and then click Properties.

2.

Click the Performance tab.

3.

In the Request queue limit section, select the Limit the kernel request queue to check box, and click the up and down arrows in the requests box to set the maximum number of queued requests.  NoteIf you clear the Limit the kernel request queue to check box, or if you set the AppPoolQueueLength metabase property to zero, IIS does not enforce a kernel request limit. Without a kernel request limit, IIS could queue an unlimited number of requests and your server could potentially run out of memory. For this reason, you should set kernel request-queue limits on all production servers.

4.

Click Apply, and then click OK.

Related Information

For more information about application pool queue-length limits, as well as other features and strategies for managing memory resources on your server, see Optimizing Memory Usage.
For information about application pools, including guidelines for creating application pools, see Creating Application Pools.
For information about features and strategies to help you monitor the health and performance of your application pools, see Ensuring Application Health in Worker Process Isolation Mode.

By:-  Chandra Mani Bahttarai

Running multiple sendmail instances on same server

February 21st, 2010

Situation:

 We want to separate core mail from “higher-risk” mail (i.e. mail sent from application servers in a DMZ) on our sendmail servers. In the event that one of our DMZ servers for which we relay mail is compromised, we do not want our mail server placed on a DNS blacklist. Therefore, we will have separate IP addresses for core mail and “higher-risk” mail. In this example, the system has only one physical network interface, so we will create and enable a virtual interface for “higher-risk” mail.

To setup multiple instances we need to have multiple IP address. We can add the multiple IPs in the linux server by using multiple network cards or by creating network card aliases. Network Aliases can be created by using the following way

1. Copy ifcfg-eth0 to ifcfg-eth0:0 (cp ifcfg-eth0 ifcfg-eth0:0)
2. Modify ifcfg-eth0:0 accordingly and assign new IP address. We can modify to ifcfg-eth0:0 same as below

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0:0
BOOTPROTO=static
BROADCAST=172.16.31.255
IPADDR=172.16.23.168
GATEWAY=172.16.16.1
NETMASK=255.255.240.0
NETWORK=172.16.16.0
ONBOOT=yes

3. Then up the newly created the network aliases, we can up it by using this command
# ifup ifcfg-eth0:0
4. To down the network aliases use this command #ifdown ifcfg-eth0:0
5. To verify newly created network aliases we can use the following command
# /sbin/ifconfig
   
By default, the sendmail mail submission agent (MSA, used to submit mail on the local system to an MTA) attempts to connect to an MTA on the localhost (127.0.0.1) interface. The second line above binds the primary sendmail instance to the localhost interface in addition to its IP address. The MSA configuration file, submit.mc, could have instead been modified to use the MTA on the primary interface or the virtual interface.

1. create copy of main sendmail.mc file to new file mx2snalert.cf
2. Modify mx2snalert.mc accordingly and add the following line in the mx2snalert.mc

define(`QUEUE_DIR’,`/var/spool/mqueue/mx2snalert/q*’)dnl
define(`confPID_FILE’,`/var/run/sendmail_mx2snalert.pid’)dnl
define(`confDOMAIN_NAME’,`mx2.snalert.net’)dnl
CLIENT_OPTIONS(`Addr=172.16.23.168′)dnl
DAEMON_OPTIONS(`Addr=172.16.23.168′)dnl
 
3. Save the mx2snalert.mc after modification
4. Create mx2snalert.cf file by using mx2snalert.mc. We can convert the mx2snalert.mc to mx2snalert.cf file by using the following command

#m4 /etc/mail/mx2snalert.mc > /etc/mail/mx2snalert.cf

5. Before starting the new instance we need to create the individual queue for individual instance.
6. We can create the individual queue by using the following commands
#mkdir /var/spool/mqueue/mx2snalert/
# mkdir /var/spool/mqueue/mx2snalert/q{1,2,3,4,5,6,7,8}
# Change the ownership of  mqueue folder.
#chown -R root:mail /var/spool/mqueue/
Also change the permission of the queue folder i.e. mqueue
#chmod –R 777 /var/spool/mqueue/

7. Reread the configuration file of the main sendmail instance.
# kill -HUP `head -1 /var/run/sendmail.pid`
8. Start the second sendmail instance.
# sendmail -L mx2snalert -C /etc/mail/ mx2snalert.cf -bd -q30m
9. We can check the status of the newly created instances by using following command

# netstat -an | grep 25
tcp  0  0 172.16.23.170:25    0.0.0.0:*  LISTEN
tcp  0  0 172.16.23.169:25    0.0.0.0:*  LISTEN
tcp  0  0 172.16.23.168:25    0.0.0.0:*  LISTEN
tcp  0  0 172.16.23.167:25    0.0.0.0:*  LISTEN

10. Now we can test new instance by sending test mail, we can send the mail by using telnet command

telnet 172.16.23.168 25
helo companydomain.net
mail from: adp@domain.com
rcpt to: mchauhan@onaxer.com
data
subject: Testing
message body
. (Enter dot to terminate the message body)

11. We can create multiple sendmail instances by using the above steps.   

Thanks
Manoj Chauhan

How to enable Sendmail Multiple Queues

February 21st, 2010

Sendmail will use by default a single mail queue. This is what most users will need, and if you don’t have any special requirement you will not care about this. Still for high traffic mail servers it might be useful to split the queue over several directories, as thousands of files in a single directory will become a performance penalty at some point and also processing the queue sequentially will become very slow. This post will show how we can implement multiple mail queues with modern sendmail versions.

Let’s start by assuming we want to use 8 mail queues. First thing is to create the actual directories as sendmail will not do this by default:
mkdir /var/spool/mqueue/q{1,2,3,4,5,6,7,8}

And fix the permissions to the ones of the original folder /var/spool/mqueue. For ex. this might look like:
chown -R smmta:smmsp /var/spool/mqueue/q*

using a default sendmail install running on debian. Fix the users to the specific ones found on your system (ls -al /var/spool/mqueue if you are uncertain of this).
Next, we need to enable the multiple queues in the sendmail configuration. For this we will edit sendmail.mc (normally found under /etc/mail) and append one line:

define(`QUEUE_DIR’, `/var/spool/mqueue/q*’)dnl

and now regenerate sendmail.cf; this is done normally running:
m4 sendmail.mc > /etc/mail/sendmail.cf

(fix your paths appropriately), or if you are using debian sendmail you can just run make all in /etc/mail.
After restarting sendmail, it will start using the multiple queues we defined. Running mailq will output each of the queues:
mailq
/var/spool/mqueue/q6 is empty
/var/spool/mqueue/q4 is empty
/var/spool/mqueue/q3 is empty
/var/spool/mqueue/q2 is empty
/var/spool/mqueue/q5 is empty
/var/spool/mqueue/q1 is empty
/var/spool/mqueue/q7 is empty
/var/spool/mqueue/q8 is empty
Total requests: 0

Thanks
Manoj Chauhan

How do I set my java classpath?

February 21st, 2010

Problem
Linux uses Red Hats java package instead of the Sun jdk.

Reason
The java interpreter from the standard Red Hat installation is placed in /usr/bin, which is in the path where Linux search for executables. This will be used be default if you don’t specify otherwise.

To find the java classes, you also have to set the java classpath to point to the java kit you want to use.

Solution
Set your PATH and CLASSPATH environment variables to reflect which java kit you want to use.

In the ITU Linux machines in 2003, the following java kits are installed: jdk1.3.1 and j2sdk1.4.1. They are placed in /usr/java.

To use jdk1.3.1, add the following lines to the file “.bashrc” in your home directory:

export PATH=/usr/java/jdk1.3.1/bin:$PATH
export JAVA_HOME=”/usr/java/jdk1.3.1″
export CLASSPATH=.:/usr/java/jdk1.3.1

If you want to use the j2sdk1.4.1, replace jdk1.3.1 with j2sdk1.4.1 and it should work.

Thanks
Manoj Chauhan

How can add mail aliases

February 21st, 2010

vi /etc/aliases
#Add following line in the aliases file
manoj:manoj.chauhan@onaxer.com,mchauhan@domain.com

after that run newaliases command in the shell, it will build the entry with aliases.db database.

Now you are able to send the mail to manoj group. 

Thanks
Manoj Chauhan

How to Check Memory Usage in Linux based Server

February 21st, 2010

Introduction:-

Memory is one of the most critical resource components on a server to ensure that the smooth and fast operation. Thus, the availability of adequate and abundant physical memory size is vital especially for any server, especially high load web host that are also running database server such as Oracle or MySQL, which is famous for memory intensive. Linux, including CentOS which is popular on cPanel and Plesk web hosting server, comes with several commands and tools to check memory usage on server.

free

free command displays amount of total, free and used physical memory (RAM) in the system, as well as shoing information on shared memory, buffers, cached memory and swap space used by the Linux kernel.

Syntax of free

free -[options]

Example usage of free

free -m

The command will display information about physical memory in MB.

free -m -s 5

The command will activate continuous polling delay at 5 seconds apart, and then display memory status in megabytes on terminal. Any floating point number for delay can be specified.

free -t -m

Same with “free -m”, but -t switch will display a line containing the totals of physical memory and swap space.

vmstat

vmstat reports report virtual memory statistics, which has information about processes, swap, free, buffer and cache memory, paging space, disk IO activity, traps, interrupts, context switches and CPU activity. With vmstat command, administrators can has instantaneous reports on memory usage.

Syntax of vmstat

vmstat -[options] [delay count]

Example usage of vmstat

vmstat

The command will display report based on averages since last reboot.

vmstat 5

The command will pool average system resources usage level for a sampling period of 5 seconds at interval of 5 seconds, except the first result that is averages since the last reboot.

top

top command displays dynamic real-time view of the running tasks managed by kernel and system information in Linux system. The memory usage stats by top command include real-time live total, used and free physical memory and swap memory with their buffers and cached memory size respectively.

Syntax and example usage of top

top

Using top is simple, simply type top at command shell, and constantly update stats page will be shown.

ps aux

ps command reports a snapshot on information of the current active processes. Advantage of ps command is that system admins will be able to see where the memory is used. ps will show the percentage of memory resource that is used by each process or task running in the system. With this command, top memory hogging processes can be identified.

Syntax and example of ps aux

aux is actually already the options for ps command to see every process on the system. So the typical command to type the following in the command shell:

ps aux

To see only the memory resources occupied by each category of processes, such as Apache httpd, MySQL mysqld or Java, use the following command:

ps aux | awk ‘{print $4″\t”$11}’ | sort | uniq -c | awk ‘{print $2″ “$1″ “$3}’ | sort -nr

The all mentioned ways of check memory usage should works on most Unix and Linux variant of operating systems. However, if you’re running a VPS (Virtual Private Server) or VDS (Virtual Dedicated Server)

Thanks
Manoj Chauhan

HOW-TO Install VMWARE server on Centos 5 or Red hat enterprise Linux 64 bit version

February 21st, 2010

Introduction:-

VMware virtualization software is an excllent choice for x86-compatible computers. They have both commercial and free version. I received few email regarding VMWARE on 64 bit Linux. Installing VMWARE server on CentOS 5 or Red hat enterprise Linux 64 bit version is a tricky business. In this small howto I will explain vmware installation on 64 bit Linux server without facing any dependencies problem.

Following instructions are tested on both RHEL 5 and CentOS 5 running 64 bit Intel / AMD hardware and software….

Server Requirements
The server is a Windows or Linux system where you install the VMWare Server software. Virtual machines can be stored on the server host or located on a network share.
Server Host Hardware VMware Server supports up to 32-way multiprocessor servers. The number of virtual machines you can run concurrently depends on the resources they require, but VMware recommends you run no more than four virtual machines concurrently per processor. You can run a maximum of 64 virtual machines concurrently on one host. The server must include the following.
• Standard x86-based server with up to 32 processors
• Hosts with 32-bit IA-32 processors, and IA-32 processors with 64-bit extensions supported
• 733MHz or faster compatible x86 processor that supports the Pentium� instruction set
Compatible processors include
• Intel: Pentium II, Pentium III, Pentium III Xeon, Pentium 4, Xeon, Xeon EM64T
• AMD™: Athlon™, Athlon XP, AMD Opteron, AMD Athlon 64
Multiprocessor systems supported

Memory
You need enough memory to run the Windows or Linux host operating system, plus memory required for each guest operating system and applications on the host and each guest; see your guest operating system and application documentation for their memory requirements.
• Minimum: 512MB
• Maximum: 64GB for Windows hosts and Linux hosts that support large memory or are PAE-enabled, 4GB for non-PAE-enabled Windows hosts or 2GB for Linux hosts with kernels in the 2.2.x series
Display
• 16-bit display adapter or higher

Host Hard Disk
• 130MB free disk space on Windows hosts required for server, VMware Management Interface, VmPerl API, VmCOM API and VMware Virtual Machine Console installation

• 20MB free disk space on Linux hosts required for server, VMware Management Interface, VmPerl API and VMware Virtual Machine Console installation

• IDE or SCSI hard drives, CD-ROM and DVD-ROM drives supported

• Guest operating systems can reside in virtual disk files or on physical (raw) disk partitions

Local Area Networking
• Any Ethernet controller that the host operating system supports

• Non-Ethernet networks are supported using built-in network address translation (NAT) or using a combination of host-only networking plus routing software on the host operating system

• A static IP address for your host machine (recommended if you want to access the server from the internet)

Remote Client Requirements
The remote client is a Windows or Linux system from which you launch the VMware Virtual Machine Console or use VMware Scripting APIs to remotely manage virtual machines on the GSX Server host. You access the VMware Management Interface to manage virtual machines on the host using a Web browser.
Hardware Requirements
• Standard x86-based computer
• 266MHz or faster processor
• 64MB RAM minimum
• 20MB (for Windows hosts) or 10MB (for Linux hosts) free disk space is required for installation of the VMware Virtual Machine Console
• 17MB free disk space is required for VMware Scripting APIs (VmCOM and VmPerl Scripting APIs) installation on Windows remote clients; 14MB is required for VmPerl API on Linux remote clients

Software — Linux Remote Client
• Standard Linux installation is required with glibc version 2.1 or higher and one of the following kernels:
• For single-processor systems: kernel 2.0.32 or higher in the 2.0.x series, or kernel in the 2.2.x, 2.4.x or 2.6.x series
• For SMP systems: kernel in the 2.2.x, 2.4.x or 2.6.x series
Note: Linux kernel 2.2.14-5.0 is not supported.
• Perl 5.005x or higher is required to use VmPerl API
• X server is required to run the VMware Virtual Machine Console on the client
• The VMware Management Interface requires one of these browsers:
• Firefox 1.x
• Mozilla 1.x
• Netscape Navigator 7.0

Lets check the kernel

$ uname -mrs

Output:

Linux 2.6.18-8.1.6.el5 x86_64

My RHEL 5 release (same kernel for CentOS):
$ cat /etc/redhat-release

Output:

Red Hat Enterprise Linux Server release 5 (Tikanga)

Make sure you have following software installed:

* Full gcc compiler and development environment
* Kernel headers and devel packages for current kernel (i.e. kernel-headers and kernel-devel)

Step # 1: Download vmware server

You can download VMWARE server here. Use wget command to download:
$ wget http://download3…

Step # 2: Install vmware server

Once downloaded use RPM command to install vmware sever, enter:

# rpm -ivh VMware-server-1.0.3-44356.i386.rpm

Step # 2: Install vmware server

Once downloaded use RPM command to install vmware sever, enter:

# rpm -ivh VMware-server-1.0.3-44356.i386.rpm

Output:

Preparing… ########################################### [100%]
1:VMware-server ########################################### [100%]

Step # 3:Install required files / libraries

You need to install following development package / files on server:

1. libXtst-devel : X.Org X11 libXtst development package
2. libXrender-devel : X.Org X11 libXrender development package

Simply use yum command to install packages:

# yum install libXtst-devel libXrender-devel

Output:

Loading “rhnplugin” plugin
Loading “installonlyn” plugin
Setting up Install Process
Setting up repositories
rhel-x86_64-server-vt-5 100% |=========================| 1.2 kB 00:00
rhel-x86_64-server-5 100% |=========================| 1.2 kB 00:00
Reading repository metadata in from local files
Parsing package install arguments
………..
….

Running Transaction
Installing: libXtst ######################### [1/8]
Installing: libXau-devel ######################### [2/8]
Installing: xorg-x11-proto-devel ######################### [3/8]
Installing: libX11-devel ######################### [4/8]
Installing: libXdmcp-devel ######################### [5/8]
Installing: libXtst-devel ######################### [6/8]
Installing: libXtst-devel ######################### [7/8]
Installing: mesa-libGL-devel ######################### [8/8]

Installed: libXtst-devel.x86_64 0:1.0.1-3.1 libXtst-devel.i386 0:1.0.1-3.1
Dependency Installed: libX11-devel.x86_64 0:1.0.3-8.0.1.el5 libXau-devel.x86_64 0:1.0.1-3.1 libXdmcp-devel.x86_64 0:1.0.1-2.1 libXtst.i386 0:1.0.1-3.1 mesa-libGL-devel.x86_64 0:6.5.1-7.2.el5 xorg-x11-proto-devel.x86_64 0:7.1-9.fc6

Complete!
Step # 4: Install xinetd

You need xinetd the extended Internet services daemon / service in order to use VMWARE console from remote computer. Use yum command to install xinetd:

# yum install xinetd

Step # 5: Configure VMWARE server

Use vmware-config.pl script to configure VMWARE networking and other aspects.

# vmware-config.pl

Output (make sure you setup VMWARE as per your requirments, following is just a sample output):

Making sure services for VMware Server are stopped.

Stopping VMware services:
Virtual machine monitor [ OK ]

You must read and accept the End User License Agreement to continue.
Press enter to display it.
……
……
will provide you with a copy of our
distribution agreement for your signature.

Do you accept? (yes/no) yes

Thank you.

Configuring fallback GTK+ 2.4 libraries.

In which directory do you want to install the mime type icons?
[/usr/share/icons]

What directory contains your desktop menu entry files? These files have a
.desktop file extension. [/usr/share/applications]
In which directory do you want to install the application’s icon?
[/usr/share/pixmaps]

Trying to find a suitable vmmon module for your running kernel.

None of the pre-built vmmon modules for VMware Server is suitable for your
running kernel. Do you want this program to try to build the vmmon module for
your system (you need to have a C compiler installed on your system)? [yes]

Using compiler “/usr/bin/gcc”. Use environment variable CC to override.

What is the location of the directory of C header files that match your running
kernel? [/lib/modules/2.6.18-8.1.6.el5/build/include]

Extracting the sources of the vmmon module.

Building the vmmon module.

Using 2.6.x kernel build system.
make: Entering directory `/tmp/vmware-config0/vmmon-only’
make -C /lib/modules/2.6.18-8.1.6.el5/build/include/.. SUBDIRS=$PWD SRCROOT=$PWD/. modules
make[1]: Entering directory `/usr/src/kernels/2.6.18-8.1.6.el5-x86_64′
CC [M] /tmp/vmware-config0/vmmon-only/linux/driver.o
CC [M] /tmp/vmware-config0/vmmon-only/linux/hostif.o
CC [M] /tmp/vmware-config0/vmmon-only/common/cpuid.o
CC [M] /tmp/vmware-config0/vmmon-only/common/hash.o
CC [M] /tmp/vmware-config0/vmmon-only/common/memtrack.o
CC [M] /tmp/vmware-config0/vmmon-only/common/phystrack.o
CC [M] /tmp/vmware-config0/vmmon-only/common/task.o
CC [M] /tmp/vmware-config0/vmmon-only/common/vmx86.o
CC [M] /tmp/vmware-config0/vmmon-only/vmcore/moduleloop.o
LD [M] /tmp/vmware-config0/vmmon-only/vmmon.o
Building modules, stage 2.
MODPOST
CC /tmp/vmware-config0/vmmon-only/vmmon.mod.o
LD [M] /tmp/vmware-config0/vmmon-only/vmmon.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.18-8.1.6.el5-x86_64′
cp -f vmmon.ko ./../vmmon.o
make: Leaving directory `/tmp/vmware-config0/vmmon-only’
The module loads perfectly in the running kernel.

Do you want networking for your virtual machines? (yes/no/help) [yes]

Configuring a bridged network for vmnet0.

Your computer has multiple ethernet network interfaces available: eth0, eth1.
Which one do you want to bridge to vmnet0? [eth0] eth1

The following bridged networks have been defined:

. vmnet0 is bridged to eth1

Do you wish to configure another bridged network? (yes/no) [no]

Do you want to be able to use NAT networking in your virtual machines? (yes/no)
[yes] no

Do you want to be able to use host-only networking in your virtual machines?
[no]

Extracting the sources of the vmnet module.

Building the vmnet module.

Using 2.6.x kernel build system.
make: Entering directory `/tmp/vmware-config0/vmnet-only’
make -C /lib/modules/2.6.18-8.1.6.el5/build/include/.. SUBDIRS=$PWD SRCROOT=$PWD/. modules
make[1]: Entering directory `/usr/src/kernels/2.6.18-8.1.6.el5-x86_64′

CC [M] /tmp/vmware-config0/vmnet-only/driver.o
CC [M] /tmp/vmware-config0/vmnet-only/hub.o
CC [M] /tmp/vmware-config0/vmnet-only/userif.o
CC [M] /tmp/vmware-config0/vmnet-only/netif.o
CC [M] /tmp/vmware-config0/vmnet-only/bridge.o
CC [M] /tmp/vmware-config0/vmnet-only/procfs.o
CC [M] /tmp/vmware-config0/vmnet-only/smac_compat.o
SHIPPED /tmp/vmware-config0/vmnet-only/smac_linux.x86_64.o
LD [M] /tmp/vmware-config0/vmnet-only/vmnet.o
Building modules, stage 2.
MODPOST
WARNING: could not find /tmp/vmware-config0/vmnet-only/.smac_linux.x86_64.o.cmd for /tmp/vmware-config0/vmnet-only/smac_linux.x86_64.o
CC /tmp/vmware-config0/vmnet-only/vmnet.mod.o
LD [M] /tmp/vmware-config0/vmnet-only/vmnet.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.18-8.1.6.el5-x86_64′
cp -f vmnet.ko ./../vmnet.o
make: Leaving directory `/tmp/vmware-config0/vmnet-only’
The module loads perfectly in the running kernel.

The default port: 902 is not free. We have selected a suitable alternative
port for VMware Server use. You may override this value now.
Remember to use this port when connecting to this server.
Please specify a port for remote console connections to use [904]

WARNING: VMware Server has been configured to run on a port different from the
default port. Remember to use this port when connecting to this server.
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
Configuring the VMware VmPerl Scripting API.

Building the VMware VmPerl Scripting API.

Using compiler “/usr/bin/gcc”. Use environment variable CC to override.

Installing the VMware VmPerl Scripting API.

The installation of the VMware VmPerl Scripting API succeeded.

Generating SSL Server Certificate

In which directory do you want to keep your virtual machine files?
[/var/lib/vmware/Virtual Machines]

The path “/var/lib/vmware/Virtual Machines” does not exist currently. This
program is going to create it, including needed parent directories. Is this
what you want? [yes]

Please enter your 20-character serial number.

Type XXXXX-XXXXX-XXXXX-XXXXX or ‘Enter’ to cancel: XYZZZ-XYZZZ-XYZZZ-ABC91
Starting VMware services:
Virtual machine monitor [ OK ]
Virtual ethernet [ OK ]
Bridged networking on /dev/vmnet0 [ OK ]

The configuration of VMware Server 1.0.3 build-44356 for Linux for this running
kernel completed successfully.

How to Start/Stop/restart VMServer

/etc/init.d/vmware stop/start/restart (stop/start/restart please change the options accordingly)

How do I manage my VMWARE server remotely?
You can now connect from local computer using vmware-server-console program to:
$ vmware-server-console &

You need to enter host name ip:port, username and password to access vmware server.
vmware-server

Thanks
Manoj Chauhan

Ganglia updated on RHEL 5.3 , Architecture x86_64

February 20th, 2010

Install ganglia Server

1. Download and install latest repository from the following URL:

rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

Note: Please install php with full lib. Support

2. Install the rrdtool by using the following command:

Install …..#rpm –Uvh rrdtool-1.2.27-3.el5.i386.rpm rrdtool-devel-1.2.27-3.el5.i386.rpm
Note : Both rpms Must be installed together .

Or

if u want to install through yum then create manual repository

Suppose machine is of 64 bit then create a manual repository with the following command

a. First check the machine architecture …..uname –i
Then Install DAG GPG key
wget http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt # download DAG GPG key
rpm –import RPM-GPG-KEY.dag.txt # import the key
rm RPM-GPG-KEY.dag.txt # clean up after ourselves

Install yum-priorities
yum install yum-priorities

Download and install package (i386 – 32bit)
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -Uhv rpmforge-release-0.3.6-1.el5.rf.i386.rpm # install the rpmforge yum repo
rm rpmforge-release-0.3.6-1.el5.rf.i386.rpm # clean up after ourselves

yum install rrdtool*………

yum install php-* (php 5.x) ,yum install php5-gd*, yum install gcc* and yum install glib*

3. rpm -ivh libconfuse-2.5-4.el5.i386.rpm
4. rpm -ivh libconfuse-devel-2.5-4.el5.i386.rpm
5. rpm -ivh libganglia-3_1_0-3.1.1-1.i386.rpm
6. rpm -ivh ganglia-gmetad-3.1.1-1.i386.rpm
7. yum install apr-devel* or rpm –ivh apr-devel-1.2.7-11.i386.rpm
8. rpm -ivh ganglia-devel-3.1.1-1.i386.rpm
9. rpm -ivh ganglia-3.1.1-1.src.rpm
10. rpm -ivh ganglia-debuginfo-3.1.1-1.i386.rpm
11. rpm -ivh ganglia-gmond-3.1.1-1.i386.rpm
12. rpm -ivh ganglia-web-3.1.1-1.noarch.rpm

There was an error collecting ganglia data (127.0.0.1:8652): fsockopen error: Connection refused

#setsebool -P httpd_can_network_connect 1
# service gmetad start
#service gmond start

Client installations:

libconfuse-2.5-4.el5.i386.rpm
libconfuse-devel-2.5-4.el5.i386.rpm
libganglia-3_1_0-3.1.1-1.i386.rpm
ganglia-gmond-3.1.1-1.i386.rpm

Edit the file /etc/ganglia/gmond.conf
Enter cluster name as entered in server configurations

service gmond start

Multicast issue use command on both server and clients

route add -host 239.2.11.71 dev eth1

On server side

*We edit the file /etc/ganglia/gmetad.conf

And enter trusted_hosts 127.0.0.1 169.229.50.165 172.16.23.182 172.16.23.183 172.16.23.184 172.16.23.185 172.16.23.186 and data_source “COMPANY” 127.0.0.1:8649 172.16.23.182:8649 172.16.23.183:8649 172.16.23.184:8649 172.16.23.185:8649 172.16.23.186:8649 are the Data source for gmetad

*Now edit /etc/hosts
Put entries of hostnames and ip addresses of client machines…

*Now add route
route add -host 222.2.11.71 dev eth1

Troubleshooting on client

#gmond –debug=9

Thanks & Regards,
Pawan & Chandra

How Write Regular Expression

February 15th, 2010

In an Regular Expression there are plenty of special characters, and it is these that both give them their power and make them appear very complicated. It’s best to build up your use of REs slowly; their creation can be something of an art form.

Here are some special RE characters and their meaning

.  # Any single character except a newline
^  # The beginning of the line or string
$  # The end of the line or string
*  # Zero or more of the last character
+  # One or more of the last character
?  # Zero or one of the last character

and here are some example matches. Remember that should be enclosed in /…/ slashes to be used.

t.e           # t followed by anthing followed by e
# This will match the
#                 tre
#                 tle
# but not te
#         tale
^f            # f at the beginning of a line
^ftp        # ftp at the beginning of a line
e$           # e at the end of a line
tle$        # tle at the end of a line
und*      # un followed by zero or more d characters
# This will match un
#                 und
#                 undd
#                 unddd (etc)
.*            # Any string without a newline. This is because
# the . matches anything except a newline and
# the * means zero or more of these.
^$         # A line with nothing in it.

There are even more options. Square brackets are used to match any one of the characters inside them. Inside square brackets a – indicates “between” and a ^ at the beginning means “not”:

[qjk]   # Either q or j or k
[^qjk]   # Neither q nor j nor k
[a-z]   # Anything from a to z inclusive
[^a-z]   # No lower case letters
[a-zA-Z]   # Any letter
[a-z]+   # Any non-zero sequence of lower case letters

At this point you can probably skip to the end and do at least most of the exercise. The rest is mostly just for reference.

A vertical bar | represents an “or” and parentheses (…) can be used to group things together:

jelly|cream   # Either jelly or cream
(eg|le)gs   # Either eggs or legs
(da)+   # Either da or dada or dadada or…

Here are some more special characters:

\n              # A newline
\t              # A tab
\w              # Any alphanumeric (word) character.
# The same as [a-zA-Z0-9_]
\W              # Any non-word character.
# The same as [^a-zA-Z0-9_]
\d              # Any digit. The same as [0-9]
\D              # Any non-digit. The same as [^0-9]
\s              # Any whitespace character: space,
# tab, newline, etc
\S              # Any non-whitespace character
\b              # A word boundary, outside [] only
\B              # No word boundary

Clearly characters like $, |, [, ), \, / and so on are peculiar cases in regular expressions. If you want to match for one of those then you have to preceed it by a backslash. So:

\|              # Vertical bar
\[              # An open square bracket
\)              # A closing parenthesis
\*              # An asterisk
\^              # A carat symbol
\/              # A slash
\\              # A backslash

Some example REs

As was mentioned earlier, it's probably best to build up your use of regular expressions slowly. Here are a few examples. Remember that to use them for matching they should be put in /.../ slashes

[01]            # Either “0″ or “1″
\/0             # A division by zero: “/0″
\/ 0            # A division by zero with a space: “/ 0″
\/\s0           # A division by zero with a whitespace:
# “/ 0″ where the space may be a tab etc.
\/ *0           # A division by zero with possibly some
# spaces: “/0″ or “/ 0″ or “/  0″ etc.
\/\s*0          # A division by zero with possibly some
# whitespace.
\/\s*0\.0*      # As the previous one, but with decimal
# point and maybe some 0s after it. Accepts
# “/0.” and “/0.0″ and “/0.00″ etc and
# “/ 0.” and “/  0.0″ and “/   0.00″ etc.
# Check for valid currency value
^([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(\.[0-9]{1,2})?$
# Check for valid email address
^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$

Exercise

Previously your program counted non-empty lines. Alter it so that instead of counting non-empty lines it counts only lines with

* the letter x
* the string the
* the string the which may or may not have a capital t
* the word the with or without a capital. Use \b to detect word boundaries.

In each case the program should print out every line, but it should only number those specified. Try to use the $_ variable to avoid using the =~ match operator explicitly.
Substitution & Translation

Just like the sed and tr utilities in Unix, you have s/// and tr/// in Perl. The former is for substitution and the later is for translation.

$bar =~ s/this/that/g;      # change this to that in $bar
$path =~ s|/usr/bin|/usr/local/bin|;

s/\bgreen\b/mauve/g;        # don’t change wintergreen

s/Login: $foo/Login: $bar/; # run-time pattern
$count = ($paragraph =~ s/Mister\b/Mrg);  # get change-count

$program =~ s {
/\*     # Match the opening delimiter.
.*?     # Match a minimal number of characters.
\*/     # Match the closing delimiter.
} []gsx; # Delete (most) C comments.

s/^\s*(.*?)\s*$/$1/;        # trim white space in $_, expensively
for ($variable) {           # trim white space in $variable, cheap
s/^\s+//;
s/\s+$//;
}

s/([^ ]*) *([^ ]*)/$2 $1/;  # reverse 1st two fields

#Note the use of $ instead of \ in the last example. Unlike sed,
#we use the \ form in only the left hand side.
#Anywhere else it’s $.

$myname = “BABU”;
$myname =~ tr/[A-Z]/[a-z]/ ; # yields babu

Splitting

Perl provides a split function to split strings, based on REs. The syntax is

split /PATTERN/,EXPR,LIMIT
split /PATTERN/,EXPR
split /PATTERN/
split

If EXPR is omitted, $_ is used. If PATTERN is also omitted, splits on whitespaces, after skipping leading whitespaces. LIMIT sets the maximum fields returned – so this can be used to split partially. Some examples are given below:

# process the password file
open(PASSWD, ‘/etc/passwd’);
while () {
($login, $passwd, $uid, $gid,
$gcos, $home, $shell) = split(/:/);
# note that $shell still has a new line.
# use chop or chomp to remove the newline
#…
($login, $passwd, $remainder) = split(/:/, $_, 3);
# here we use LIMIT to set the number of fields

}

We also have join which is the opposite of split. For fixed length strings, we have unpack and pack functions.

The regular expressions basic syntax

To use regular expressions first you need to learn the syntax of the patterns. We can group the characters inside a pattern like this:

  • Normal characters which match themselves like hello
  • Start and end indicators as ^ and $
  • Count indicators like +,*,?
  • Logical operator like |
  • Grouping with {},(),[]

An example pattern to check valid emails looks like this:

Code:
^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$

The code to check the email using Perl compatible regular expression looks like this:

Code:
1. $pattern = "/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/"; 2. $email = "jim@demo.com"; 3. if (preg_match($pattern,$email)) echo "Match"; 4. else echo "Not match";

And very similar in case of POSIX extended regular expressions:

Code:
1. $pattern = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$"; 2. $email = "jim@demo.com"; 3. if (eregi($pattern,$email)) echo "Match"; 4. else echo "Not match";

Now let’s see a detailed pattern syntax reference:

Regular expression (pattern) Match (subject) Not match (subject) Comment
world Hello world Hello Jim Match if the pattern is present anywhere in the subject
^world world class Hello world Match if the pattern is present at the beginning of the subject
world$ Hello world world class Match if the pattern is present at the end of the subject
world/i This WoRLd Hello Jim Makes a search in case insensitive mode
^world$ world Hello world The string contains only the “world”
world* worl, world, worlddd wor There is 0 or more “d” after “worl”
world+ world, worlddd worl There is at least 1 “d” after “worl”
world? worl, world, worly wor, wory There is 0 or 1 “d” after “worl”
world{1} world worly There is 1 “d” after “worl”
world{1,} world, worlddd worly There is 1 ore more “d” after “worl”
world{2,3} worldd, worlddd world There are 2 or 3 “d” after “worl”
wo(rld)* wo, world, worldold wa There is 0 or more “rld” after “wo”
earth|world earth, world sun The string contains the “earth” or the “world”
w.rld world, wwrld wrld Any character in place of the dot.
^.{5}$ world, earth sun A string with exactly 5 characters
[abc] abc, bbaccc sun There is an “a” or “b” or “c” in the string
[a-z] world WORLD There are any lowercase letter in the string
[a-zA-Z] world, WORLD, Worl12 123 There are any lower- or uppercase letter in the string
[^wW] earth w, W The actual character can not be a “w” or “W”

Thanks & Regards,
Manoj Chauhan

How Change senders email address in mutt

February 2nd, 2010

i have created the .muttrc in roots home directory and gave the option

set from = “xyz@domain.com”

but still when i run mutt it gives me the senders address
as
root<xyz@domain.com>
now what???

To change the from email address while using mutt
create a .muttrc in the users home directory if it doesnot exist, then enter the feild
set realname=”username” this will change the name in the senders name .

Thanks
Manoj Chauhan