Tuesday, December 7, 2010

Spring MVC Architechture









Spring FORM Tag Library

Spring MVC provides a JSP tag library (Spring Form) for making it easier to bind form elements to Model data. Spring Framework also provides you with some tags for evaluating errors, setting themes and outputting internationalized messages.



Syntax to use Spring Form tag library

	<%@taglib  uri="http://www.springframework.org/tags/form" prefix="form">

Form tags used in this example

-Renders an HTML 'form' tag and exposes a binding path to inner tags for binding.

-Renders an HTML 'input' tag with type 'text' using the bound value.

-Renders field errors in an HTML 'span' tag.

-Renders an HTML 'input' tag with type 'password' using the bound value.

-Renders an HTML 'input' tag with type 'radio'.

-Renders an HTML 'select' element. Supports databinding to the selected option.

-Renders a single HTML 'option'. Sets 'selected' as appropriate based on bound value.

-Renders an HTML 'textarea'.

-Renders an HTML 'input' tag with type 'checkbox'.

Simple Registration Form Example

1.Modify the web.xml to configure the Dispatcher Servlet.

web.xml













































false



registration">









index



success























3.Create a Jsp file for taking input from the user index.jsp which contains all the form fields with Spring Form tags.

index.jsp



<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>











Welcome to Spring Web MVC project







Spring Form tags Example







User Name:





Password:





First Name:



Last Name:



Gender: Male

Female



Country :

India

USA

Australia





Address:



Select any :

Check Box1



Check Box2





















4.Create another Jsp file success.jsp which is a View for Spring to display the output. In this file we use Expression Language to display the details.

success.jsp



<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@page import="java.util.Enumeration"%>











Spring Form Tags Example





Spring Form tags examples





User Name: ${uname}



First Name: ${fname}



Last Name: ${lname}



Gender: ${gender}



Country: ${country}



Address: ${addr}



Selected Check box: ${cb}











5.Create a Java class file Registration.java which contains the business logic for registration application. Here this file contains 8 private variables with their respective getter and setter methods to store the details for registration.

Registration.java



public class Registration {



private String username;

private String password;

private String fname;

private String lname;

private String gender;

private String country;

private String addr;

private String cb;



public String getAddr() {

return addr;

}



public void setAddr(String addr) {

this.addr = addr;

}



public String getCb() {

return cb;

}



public void setCb(String cb) {

this.cb = cb;

}



public String getCountry() {

return country;

}



public void setCountry(String country) {

this.country = country;

}



public String getGender() {

return gender;

}



public void setGender(String gender) {

this.gender = gender;

}



public Registration() {

}



public String getFname() {

return fname;

}



public void setFname(String fname) {

this.fname = fname;

}



public String getLname() {

return lname;

}



public void setLname(String lname) {

this.lname = lname;

}



public String getPassword() {

return password;

}



public void setPassword(String password) {

this.password = password;

}



public String getUsername() {

return username;

}



public void setUsername(String username) {

this.username = username;

}



}





6.Create a RegistrationFormController.java file which extends SimpleFormController to control the user request and return respective ModelAndView object.

RegistrationFormController.java





import org.springframework.web.servlet.ModelAndView;

import org.springframework.web.servlet.mvc.SimpleFormController;



public class RegistrationFormController extends SimpleFormController {



@Override

protected ModelAndView onSubmit(Object command) throws Exception {



Registration reg=(Registration)command;



String uname=reg.getUsername();

String fname=reg.getFname();

String lname=reg.getLname();



String gender=reg.getGender();

String country=reg.getCountry();

String cb=reg.getCb();

String addr=reg.getAddr();



ModelAndView mv = new ModelAndView(getSuccessView());



mv.addObject("uname",uname);

mv.addObject("fname",fname);

mv.addObject("lname",lname);

mv.addObject("gender",gender);

mv.addObject("country",country);

mv.addObject("cb",cb);

mv.addObject("addr",addr);



return mv;

}



}



7.Create a registrationValidator.java file to validate the form fields like username and password should not be empty.DispatcherServlet is responsible to give property to add Validator to the user request and perform validation.

registrationValidator.java



import org.springframework.validation.Errors;

import org.springframework.validation.Validator;



public class registrationValidator implements Validator

{



public boolean supports(Class cl) {

return Registration.class.isAssignableFrom(cl);



}



public void validate(Object ob, Errors errors) {

Registration reg=(Registration)ob;

if (reg.getUsername() == null || reg.getUsername().length() == 0) {

errors.rejectValue("username", "error.empty.username");

}



else if (reg.getPassword() == null || reg.getPassword().length() == 0) {

errors.rejectValue("password", "error.empty.password");

}



}



}



8.Create or Modify messages.properties file which contains the messages for their respective keys.In this file we write messages for two keys empty username and empty password.

messages.properties



error.empty.username=Please Enter User name

error.empty.password=Please Enter Password

9.Building and running the application





Friday, September 10, 2010

Very Secure File Transfer Protocol Daemon (VSFTPD)

File Transfer Protocol (FTP) is considered as the primary method used to transfer files over a network from computer to computer. FTP uses a client/server model. An FTP client is used to access the FTP server, and as a server, FTP provides access to files or storage.

Very Secure File Transfer Protocol Daemon (vsFTPd) is a fast and secure FTP daemon which is the preferred FTP server for Red Hat Enterprise Linux.

How to Install Very Secure File Transfer Protocol Daemon (vsFTPd)

You can use the rpm command to install vsFTPd as shown below.

[root@RHEL04 ~]# rpm -Uvh vsftpd-2.0.5-10.el5.i386.rpm

OR by using the yum command, if you have configured yum properly.


[root@RHEL04 ~]# yum –y install vsftpd


Once vsFTPd is installed, make sure it starts the next time you boot Linux. You can use the ‘chkconfig’ command to make the vsFTPd start working when you reboot the system.

[root@RHEL04 ~]# chkconfig vsftpd on

Main files and directories Installed with vsftpd

The vsftpd RPM installs the daemon (/usr/sbin/vsftpd), its configuration and related files, as well as FTP directories onto the system.

The following list shows the main files and directories related to vsftpd configuration:

• /etc/rc.d/init.d/vsftpd: The initialization script (initscript) used by the /sbin/service command to start, stop, or reload vsftpd.

• /etc/pam.d/vsftpd: The Pluggable Authentication Modules (PAM) configuration file for vsftpd.

• /etc/vsftpd/vsftpd.conf: The main configuration file for vsftpd.

• /etc/vsftpd/ftpusers: A list of users not allowed to log into vsftpd. By default, this list includes the root, bin, and daemon users, among others, since sending the username and password credentials of sensitive users using clear text is not secure.

• /etc/vsftpd/user_list: This file can be configured to either deny or allow access to the users listed, depending on whether the userlist_deny directive is set to YES (default) or NO in /etc/vsftpd/vsftpd.conf. If /etc/vsftpd.user_list is used to grant access to users, the usernames listed must not appear in /etc/vsftpd.ftpusers.

• /var/ftp/: — The directory containing files served by vsftpd. It also contains the /var/ftp/pub/ directory for anonymous users. Both directories are world-readable, but writable only by the root user.

vsFTPd configuration file /etc/vsftpd/vsftpd.conf

All configuration of vsftpd can be done by its configuration file, /etc/vsftpd/vsftpd.conf. Each directive is on its own line within the file and follows the following format:

=

The lines starting with‘#’ are comments.

vsFTPd daemon Options in /etc/vsftpd/vsftpd.conf

The following is a list of directives which control the overall behavior of the vsftpd daemon.

listen: When enabled, vsftpd runs in standalone mode. This value is set to YES by default. This directive cannot be used in conjunction with the listen_ipv6 directive.

listen_ipv6: When enabled, vsftpd runs in standalone mode, but listen only to IPv6 sockets. This directive cannot be used in conjunction with the listen directive.

The default value is NO.

Log-in Options and Access Controls in /etc/vsftpd/vsftpd.conf

Anonymous access features can be changed for your FTP server by editing the vsftpd.conf file and changing related entries to YES or NO in the file. The main setting related with anonymous access are:

anonymous_enable: Enabled by default. Use a setting of NO, and then restart the server to turn off anonymous access.

anon_mkdir_write_enable: Allows or disallows creating of new directories.

anon_other_write_enable: Allows or disallows deleting or renaming of files and directories.

anon_upload_enable: Controls whether anonymous users can upload files (also depends on the global write_enable setting).

anon_world_readable_only: Allows anonymous users to download only files with world-readable (444) permission

no_anon_password: When enabled, the anonymous user is not asked for a password. The default value is NO.

banner_file: Specifies the file containing text displayed when a connection is established to the server. This option overrides any text specified in the ftpd_banner directive.

cmds_allowed — Specifies a comma-delimited list of FTP commands allowed by the server. All other commands are rejected.

ftpd_banner: When enabled, the string specified within this directive is displayed when a connection is established to the server. This option can be overridden by the banner_file directive. By default vsftpd displays its standard banner.

local_enable: When enabled, local users are allowed to log into the system.

userlist_deny: If userlist_deny=NO, only allow users in userlist_file. If userlist_deny=YES (default), never allow users in userlist_file, and do not even prompt for a password.

userlist_enable: When enabled, the users listed in the file specified by the userlist_file directive are denied access.

userlist_file: Specifies the file referenced by vsftpd when the userlist_enable directive is enabled. This file is created when vsftp is installed and is located in /etc/vsftpd/user_list.

ftp_username: Specifies the local user account (listed in /etc/passwd) used for the anonymous FTP user. The home directory specified in /etc/passwd for the user is the root directory of the anonymous FTP user. The default user is ftp and default home folder is /var/ftp/.

chroot_list_enable: When enabled, the local users listed in the file specified in the chroot_list_file directive are placed in a chroot jail upon log in. If enabled in conjunction with the chroot_local_user directive, the local users listed in the file specified in the chroot_list_file directive are not placed in a chroot jail upon log in. The default value is NO.

chroot_list_file: Specifies the file containing a list of local users referenced when the chroot_list_enable directive is set to YES. The default value is /etc/vsftpd/chroot_list.

chroot_local_user: When enabled, local users are change-rooted to their home directories after logging in. The default value is NO.

Other important options in /etc/vsftpd/vsftpd.conf

dirlist_enable: When enabled, users are allowed to view directory lists.

write_enable: When enabled, FTP commands which can change the file system are allowed.

accept_timeout: Specifies the amount of time for a client using passive mode to establish a connection. The default value is 60.

anon_max_rate: Specifies the maximum data transfer rate for anonymous users in bytes per second. The default value is 0, which does not limit the transfer rate.

connect_timeout: Specifies the maximum amount of time a client using active mode has to respond to a data connection, in seconds. The default value is 60.

idle_session_timeout: Specifies the maximum amount of time between commands from a remote client. Once triggered, the connection to the remote client is closed.

listen_address: Specifies the IP address on which vsftpd listens for network connections. There is no default value for this directive.

listen_address6: Specifies the IPv6 address on which vsftpd listens for network connections when listen_ipv6 is set to YES. There is no default value for this directive.

listen_port: Specifies the port on which vsftpd listens for network connections. The default value is 21.

local_max_rate: Specifies the maximum rate data is transferred for local users logged into the server in bytes per second. The default value is 0, which does not limit the transfer rate.

max_clients: Specifies the maximum number of simultaneous clients allowed to connect to the vsFTPd server when it is running in standalone mode. Any additional client connections to the vsFTPd server would result in an error message. The default value is 0, which does not limit connections.


Wednesday, September 1, 2010

Users and Groups

Although adding users and groups seems like a simple task on the surface, it does require forward planning and preparation for a large user group such as one for a large company or corporation or for an organization that requires users to have access to multiple computers throughout the same building or even a set of worldwide offices.

In addition to a Red Hat Enterprise Linux system having a username for each user allowed access to a system, each system has user groups. A user group is a group of one or more users. A user can be a member of more than one group.

Each user on a Red Hat Enterprise Linux system is assigned a unique user identification number, also known as a UID. UIDs below 500 are reserved for system users such as the root user. System users also include those added for a specific service such as the nfsnobody, rpc and rpcuser users for the NFS service.

By default in Red Hat Enterprise Linux, when a user is added, a private user group is created—meaning that a user group of the same name is created and that the new user is the sole user in that group.

Adding and Modifying Users
Configure the username, full name, and password for the new user. The default login shell for new users is bash. By default, the directory /home// is created as the user’s home directory, and a private group is created for the user.

Adding Users
To add a new user, use the useradd command. The basic syntax is useradd . The username is the only information required to add a new user. The useradd command creates the account, but the account is locked. To unlock the account and create a password for the user, use the command passwd . By default, the user’s home directory is created and the files from /etc/skel/ are copied into it. The two exceptions are if the -M
option is used and if the home directory already exists.



Password Aging
Optionally, password aging can also be configured with the chage command. If the chage
command is immediately followed by a username, the administrator will be interactively
prompted for the password aging

[root@Matrix ~]# chage swathi
Changing the aging information for swathi
Enter the new value, or press ENTER for the default
Minimum Password Age [0]: 15
Maximum Password Age [99999]: 15
Last Password Change (YYYY-MM-DD) [2010-09-01]: 2010-09-02
Password Expiration Warning [7]: 5
Password Inactive [-1]: -1
Account Expiration Date (YYYY-MM-DD) [1969-12-31]: 2010-09-17

[root@Matrix ~]# chage -l swathi
Last password change : Sep 02, 2010
Password expires : Sep 17, 2010
Password inactive : never
Account expires : Sep 17, 2010
Minimum number of days between password change : 15
Maximum number of days between password change : 15
Number of days of warning before password expires : 5

Deleting Users
The userdel command is available for deleting users using the userdel syntax. If no command line options are used, the user is deleted and can no longer log into the system. The private user group for the user is also deleted, and the user is removed from any other groups of which he was a member. However, the user’s home directory and any other files the user owned are not deleted from the system. To remove the user’s home directory and mail spool, use the userdel -r command. All other files owned by the user must be deleted manually if the administrator needs them removed. However, use caution when removing files owned by a removed user, they might be shared files still needed by others in the group.

Any remaining files will still exist with the user’s old UID, so be careful when creating new users.
If the UID is reused for a different user, you might be giving the new user access to the old
user’s files because file permissions are based on the UID and GID associated with the file.


Managing Groups
A new group with the same name as the user is created by default when a new user is added. This new group is referred to as a private user group. Every user has a default group, which is usually the user’s private user group, but every user can also be a member of more than one group. When a file or directory is created by a user, the user’s default group becomes the group associated with the file unless the directory is configured to with the s option to chmod that sets the group ID of files in that directory upon creation. The additional groups a user is a member of allows the user to
have access to files associated with the group and with the proper group file permissions.
A unique integer known as a GID is associated with each group. GIDs below 500 are reserved for system groups just like UIDs below 500 are reserved for system users.

Adding Groups
The groupadd command can be used to add user groups to the system. The basic syntax is
groupadd . If no command-line options are used, the group is created with the next available GID above 499. To specify a GID, use the groupadd -g command. To add a system group, use the groupadd -r command. The first available GID below 500 is used for the system group. To add a system group and specify the GID, use the groupadd -r -g command. Even if you specify a GID for the system group, the GID still needs to be below 500 to follow the numbering convention.

To add users to a group, use the usermod -G command

Modifying Groups
Other than adding users to the group, the name of the group and the GID of the group
can be changed with the groupmod command. To change the GID of a group, use the
groupmod -g command. To change the name of the group, use the
groupmod -n command.
Red Hat Enterprise Linux also includes the gpasswd command for managing groups. It
allows an administrator to configure group administrators, group members, and a group
password. Group administrators can add and delete users as well as set, change, or remove
the group password. A group can have more than one group administrator.
To add group administrators, use the gpasswd -A command, where
is a comma-separated list of existing users you want to be group administrators.
Don’t use any spaces between the commas.
The root user or a group administrator can add users to the group with the gpasswd -a
command. Using this method, only one user can be added at a time.
Similarly, to remove a user from a group, use the gpasswd -d command.
t is also possible for the root user (not a group administrator) to modify the members of a
group with the gpasswd -M command, where is a comma-
separated list of all the users in the group. Notice the word all. When this command is
executed, the group members list changes to the users listed in this command. Any exist
ing members not listed will be removed.
To add or change the password for a group, the root user or a group administrator can use
the gpasswd command. When changing the password, the old password is
not needed. To remove the group password, use the
gpasswd -r command.
If a user is a member of a group, she can use the newgrp command to make
that group her default group for that login session. If the group has a password, the user
must enter the correct password before successfully switching groups. If the group has a
password, users who aren’t members of the group can also make the group their default
group with the newgrp command. If the group doesn’t have a password configured, only
users who are members of the group can use the newgrp command to change groups for
that login session. To disable the use of the newgrp command for a group, use the gpasswd
-R command.

How It All Works
A list of all local users is stored in the /etc/passwd file. This file is in plain text format and
is readable by anyone logged in to the system because it is referenced by user-accessible
utilities such as ls and who to map user and group IDs to usernames and group names.
Each user is listed on a separate line, with the following format:
username:password:uid:gid:real_name:/home/directory:shell

If shadow passwords are used (the default), the encrypted passwords are stored in the
/etc/shadow file, readable only by root for security reasons. This file can also store
optional password expiration data.
All user groups are stored in the /etc/group file, readable by everyone but only writable
by root for the same reason /etc/passwd has these permissions—user utilities need to be
able to map group IDs to group names. Each group is listed on a separate line in the
following format:
groupname:password:gid:users

The group name is the actual name of the user group, the password field contains the x
character if shadow passwords are used or the encrypted password if shadow passwords
are not used. The gid is the unique group ID for the group, and the users field is a
comma-delimited list of users in the group.
If shadow passwords are used for group passwords (the default), they are stored in
/etc/gshadow, a file readable only by the root user.
When a new user is added, files from the /etc/skel/ directory are copied to the user’s
home directory unless the administrator chooses not to create one.

NOTE
By default, a home directory is created when a user is added. If the user’s home direc
tory already exists (for example, the /home/ directory was preserved during reinstalla
tion), the files from /etc/skel/ are not copied to the existing home directory so that
the existing files are not overwritten. This behavior has changed in recent versions of
useradd, so use caution when performing this same operation on older versions of
Red Hat Enterprise Linux.
The default values used when adding a user are stored in the /etc/default/useradd file.
Additional default values for creating users and groups are located in the /etc/login.defs
file. This file is documented with comments above each directive, which should be easy
to follow if modifications are needed. The following can be modified with options from
this file:
. Mail spool directory
. Maximum number of days a password can be used
. Minimum number of days between password changes
. Minimum password length accepted
. Number of days to warn user before password expires
. Maximum UID for automatic selection by useradd
. Minimum UID for automatic selection by useradd
. Maximum GID for automatic selection by groupadd
. Minimum GID for automatic selection by groupadd
. Whether to remove cron and print jobs owned by user when user is removed
. Whether or not to create the home directory by default

Deleting Groups
To delete an existing group, use the groupdel command. The group is removed, and the users in the group are no longer members of the group.

Monday, August 9, 2010

Installing Apache Webserver on Fedora 12

1. Download the latest stable version of Apache webserver from the apache website
2. Create a directory apache2 in your home directory and copy the tar file there
(This is not mandatory, this is just to ease your installation)
[sridhar@Matrix ~]$ mkdir apache2
3. change to root
[sridhar@Matrix ~]$ su Password: [root@Matrix sridhar]#
4. copy the download file to the newly created apache2 folder
in this case
[root@Matrix ~]# cp /home/sridhar/Downloads/httpd-2.2.16.tar.gz /home/sridhar/apache
5. Unzip the file
[root@Matrix ~]# gzip -d httpd-2.2.16.tar.gz
6. Untar the file
[root@Matrix ~]# tar -xvf httpd-2.2.16.tar
7. [root@Matrix ~]# ./configure --prefix=/opt/apache2
This will install apache in /opt/apache2 location, default location is /usr/local/apache2
8. [root@Matrix ~]# make
9. [root@Matrix ~]# make install
10. [root@Matrix ~]# /opt/apache2/bin/apachectl start

Open a webbrowser and type in http://localhost, you must be able to see this

Sunday, August 1, 2010

Cron Job

Cron is a time-based job scheduler utility for automating certain tasks in Unix-like operating systems. Cron enables users to schedule jobs (commands or shell scripts) to run periodically at certain time or date. It is commonly used to automate system maintenance or administration. For example if you would like to create backups of certain files or directories each night, you can use Cron to automate this.

Cron stores it's enteries in the crontab (cron table) file. This is generally located in the /etc directory. Each user can have their own crontab which would be stored in /var/spool/cron/. To edit a users crontab entry, simply log on to the system for that particular user and type crontab -e. The default editor for the 'crontab -e' command is vi. If you are not familiar with VI you can change the default editor by running the following command export VISUAL='editor'. Of course you must replace editor with your favorite text editor (nano, pico, joe etc). Or you could always learn how to use VI

Each line of a crontab file represents a job and is composed of a CRON expression, followed by a shell command to execute. Cron job has seven fields
1st field denotes Minutes ( 0 - 59 )
2nd field denotes Hours ( 0 - 23 )
3rd field denotes Day of the month ( 1 - 31 )
4th field denotes Month ( 1 - 12 ) or ( Jan, feb, mar, apr, ......)
5th field denotes Day of the week ( 0 - 7 ) or ( sun, mon, tue, wed, ......) Note ( 0 & 7 both denote Sunday)
6th field contains user User who runs the command.
7th field contains command Command that needs to be run. This field may contain multiple words or spaces.

There are several special predefined values which can be used to substitute the CRON expression.

Entry : @yearly (or @annually)
Description : Run once a year
Equivalent To : 0 0 1 1 *

Entry : @monthly
Description : Run once a month
Equivalent To : 0 0 1 * *

Entry : @weekly
Description : Run once a week
Equivalent To : 0 0 * * 0

Entry : @daily
Description : Run once a day
Equivalent To : 0 * * *

Entry : @midnight
Description : (same as @daily)
Equivalent To : 0 0 * * *

Entry : @hourly
Description : Run once an hour
Equivalent To : 0 * * * *

If both the dom and dow are specified, the command will be executed when
either of the events happen.
e.g.
* 12 16 * Mon root cmd
Will run cmd at midday every Monday and every 16th, and will produce the
same result as both of these entries put together would:
* 12 16 * * root cmd
* 12 * * Mon root cmd

Vixie Cron also accepts lists in the fields. Lists can be in the form, 1,2,3
(meaning 1 and 2 and 3) or 1-3 (also meaning 1 and 2 and 3).
e.g.
59 11 * * 1,2,3,4,5 root backup.sh
Will run backup.sh at 11:59 Monday, Tuesday, Wednesday, Thursday and Friday,
as will:
59 11 * * 1-5 root backup.sh

Cron also supports 'step' values.
A value of */2 in the dom field would mean the command runs every two days
and likewise, */5 in the hours field would mean the command runs every
5 hours.
e.g.
* 12 10-16/2 * * root backup.sh
is the same as:
* 12 10,12,14,16 * * root backup.sh

*/15 9-17 * * * root connection.test
Will run connection.test every 15 mins between the hours or 9am and 5pm

Lists can also be combined with each other, or with steps:

* 12 1-15,17,20-25 * * root cmd
Will run cmd every midday between the 1st and the 15th as well as the 20th
and 25th (inclusive) and also on the 17th of every month.

* 12 10-16/2 * * root backup.sh
is the same as:
* 12 10,12,14,16 * * root backup.sh

When using the names of weekdays or months, it isn't case sensitive, but only
the first three letters should be used, e.g. Mon, sun or Mar, jul.

Comments are allowed in crontabs, but they must be preceded with a '#', and
must be on a line by them self.

Controlling Access to cron

Cron has a built in feature of allowing you to specify who may, and who
may not use it. It does this by the use of /etc/cron.allow and /etc/cron.deny
files. These files work the same way as the allow/deny files for other
daemons do. To stop a user using cron, just put their name in cron.deny, to
allow a user put their name in the cron.allow. If you wanted to prevent all
users from using cron, you could add the line ALL to the cron.deny file:

root@Matrix # echo ALL >>/etc/cron.deny

If you want user cog to be able to use cron, you would add the line cog
to the cron.allow file:

root@Matrix # echo cog >>/etc/cron.allow

If there is neither a cron.allow nor a cron.deny file, then the use of cron
is unrestricted (i.e. every user can use it). If you were to put the name of
some users into the cron.allow file, without creating a cron.deny file, it
would have the same effect as creating a cron.deny file with ALL in it.
This means that any subsequent users that require cron access should be
put in to the cron.allow file.

Saturday, July 17, 2010

/etc Directory

/etc directory contains configuration files of all the programs and services that run in a linux machine. A Linux service is an application (or set of applications) that runs in the background waiting to be used, or for carrying out essential tasks. This directory is one of the most used directories by the system administrators. There are many useful files and directories that are used by a system administrator on a day-day basis.

How does a system administrator tell what services are running, and more importantly, how does he set up one of his own?

Let's start by looking at how the system is set up, and in particular at the directory /etc/rc.d. Here you will find either a set of files named rc.0, rc.1, rc.2, rc.3, rc.4, rc.5, and rc.6, or a set of directories named rc0.d, rc1.d, rc2.d, rc3.d, rc4.d, rc5.d, and rc6.d. You will also find a file named /etc/inittab. The system uses these files (and/or directories) to control the services to be started.

The file /etc/inittab will have entries something like this:

id:4:initdefault:l

0:0:wait:/etc/rc.d/rc.0l

6:6:wait:/etc/rc.d/rc.6x

1:4:wait:/etc/rc.d/rc.4


The boot process uses these parameters to identify the default runlevel and the files that will be used by that runlevel. In this example, runlevel 4 is the default and the scripts that define runlevel 4 can be found in /etc/rc.d/rc.4.

Runlevel is the point at which the system is entered. Runlevel 1 is the most basic configuration (Simple single user access using an text interface), while Runlevel 5 is the most advanced (multi-user, networking and a GUI front end). Runlevels 0 and 6 are used for halting and rebooting the system.

System Boot Process:
When booting multi-user, the kernel runs init (located in /sbin/init), which spawns a shell (/bin/sh) to run /etc/rc, which contains commands to check the consistency of the file-systems, mount the disks, start up system processes, etc. /etc/rc invokes /etc/netstart to configure the network and any associated services, and /etc/rc.local (if it exists) for locally added services.
After /etc/rc has successfully completed, init forks a copy of itself for each terminal in /etc/ttys, usually running /usr/libexec/getty on them. Administrative configuration of system services is controlled by editing the scripts (/etc/rc, /etc/rc.local, /etc/netstart). In some instances, only shell variables need to be changed, in others commands are added, changed, or removed.



/etc/rc

Saturday, July 10, 2010

Most Commonly Used Linux Commands



Host Information

uname .............. Print system information
hostname ........... Print the system's hostname
ifconfig ........... Display or set network interface configuration
host ............... Lookup DNS information
nslookup ........... Lookup DNS information (deprecated)
whois .............. Lookup domain registrants
ping ............... Test reachability of a host
traceroute ......... Display network path to a host

Process Management

ps ................. List processes
w .................. List users' processes
uptime ............. View the system load, amount of time it has been running, etc.
top ................ Monitor processes
free ............... Display free memory
kill ............... Send signals to processes
killall ............ Kill processes by name
nice ............... Set a processes nice value
renice ............. Set the nice value of a running process.
at ................. Run a job at a specific time
crontab ............ Schedule repeated jobs
batch .............. Run a job as the system load premits
watch .............. Run a programm at specific intervals
sleep .............. Wait for a specified interval of time

Disks and File Systems

df ................ Display free space
du ................ Display disk usage
mount ............. Mount a filesystem
fsck .............. Check and repair a filesystem
sync .............. Flush disk caches

File and Directory Basics

cd ................. Change Directory
cp ................. Copy files
file ............... Determine a file's content
ls ................. List files or directories
ln ................. Make a link to a file
mkdir .............. Make a directory
rmdir .............. Remove a directory
mv ................. Move a file
rm ................. Remove a file

Locate Files

find .............. Find files and directories
which ............. Locate commands within your search path
whereis ........... Locate standard file

File Management

ls ................ Display file attributes
stat .............. Display file attributes
wc ................ Count the number of lines, words and characters in a file
file .............. Identify file types
touch ............. Set the time stamp of a file or directory
chgrp ............. Change the group of a file
chmod ............. Change the permissions (mode) of a file
chown ............. Change the owner of a file
chattr ............ Change advanced file attributes
lsattr ............ Display advanced file attributes

File Viewing

cat ............... Display the contents of file
less .............. Page through files
head .............. Show the top portion of a file
more .............. Display screenfuls of a file
tail .............. Display bottom portion of a file
nl ................ Count the number of lines in a file
wc ................ Count the number of lines, words and characters in a file
od ................ View a binary file
tee ............... Display output on stdout and write it to a file simultaneously

File Manipulation

csplit ............ Split a file
cut ............... Display columns of a file
paste ............. Append columns in a file
sort .............. Sort a file
tr ................ Translate chracters in a file
uniq .............. Find unique or repeated lines in a file
xargs ............. Process multiple arguements

File Comparison

diff .............. Find differences in two files
dircmp ............ Compare two directories
cmp ............... Compare two files
comm .............. Compare sorted files
md5sum ............ Compute the MD5 checksum of a file
sum ............... Compute the checksum of a file

File Compression and Archiving

gzip .............. Compress a file using GNU Zip
gunzip ............ Uncompress a file using GNU Zip
compress .......... Compress a file using UNIX compress
uncompress ........ uncompress a file using UNIX compress
bzip2 ............. Compress a file using block-sorting file compressor
bunzip2 ........... Uncompress a file using block-sorting file compressor
zip ............... Compress a file using Windows/DOS zip
unzip ............. Uncompress a file using Windows/DOS zip
tar ............... Read/Write (tape) archives
cpio .............. Copy files to and from archives
dump .............. Dump a disk to tape
restore ........... Restore a dump
mt ................ Tape control programme

Printing

lpr ............... Print files
lpq ............... View the print queue
lprm .............. Remove print jobs
lpc ............... Line printer control program